Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 *    Transform date or time to various formats
 * 
 * @copyright   Copyright (C) 2012 - 2013 Information Technology Institute ITI-CERTH. All rights reserved.
 * @license     GNU Affero General Public License version 3 or later; see LICENSE.txt
 * @author      Dimitrios Ververidis for the Multimedia Group (http://mklab.iti.gr). 
 *
 */

import java.text.DateFormatSymbols;

import android.content.res.Configuration;

public class Main {
    /**
     * Convert "Friday X Month Year" to "YYYY-MM-DD"  
     * 
     * @param Date_STR
     * @param conf
     * @return
     */
    public static String dateSTR2Num(String Date_STR, Configuration conf) {

        String[] DateARR = Date_STR.split(" ");

        String DayNo = DateARR[1];
        String YearSTR = DateARR[3];

        //----- Month problem ------
        String MonthSTR = DateARR[2];

        DateFormatSymbols symbols = new DateFormatSymbols(conf.locale);
        String[] monthNames = symbols.getMonths();

        int iMonth = 0;

        for (int i = 0; i < monthNames.length; i++)
            if (MonthSTR.equals(monthNames[i]))
                iMonth = i;

        String MonthNo = Integer.toString(iMonth + 1);

        if (MonthNo.length() < 2)
            MonthNo = "0" + MonthNo;

        return YearSTR + "-" + MonthNo + "-" + DayNo;
    }
}