Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Calendar;

public class Main {
    private static final String DASH = "-";

    public static long formatTimeString(String timeString) {
        long time = 0;
        if (timeString == null || timeString.length() < 1) {
            return time;
        }
        try {
            String[] array = timeString.split(DASH);
            int year = Integer.valueOf(array[0]);
            int month = Integer.valueOf(array[1]);
            int day = Integer.valueOf(array[2]);

            Calendar calendar = Calendar.getInstance();
            calendar.set(Calendar.YEAR, year);
            calendar.set(Calendar.MONTH, month);
            calendar.set(Calendar.DAY_OF_MONTH, day);

            time = calendar.getTimeInMillis();

        } catch (Exception e) {
            e.printStackTrace();
        }

        return time;
    }
}