JAVA Calendar

Made a big mistake to convert from year,month,day to millisecondTime:


For ex.

if you wanna convert [year, month, day] to a Calendar object, basically you need to minus one for the month since the 1 in the Calendar is February…damn..

Calendar beginTime = Calendar.getInstance();
beginTime.set(year, month - 1, day, hour, min, sec);



Convert milliseconds to Date Format:

public static String getDate(long milliSeconds) {
    SimpleDateFormat formatter = new SimpleDateFormat(
            "dd/MM/yyyy hh:mm:ss a");
    Calendar calendar = Calendar.getInstance();
    return formatter.format(calendar.getTime());

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s