how to use joda timing in java

74 Views Asked by At

currently i am using calendar type..

GregorianCalendar gcalendar = new GregorianCalendar();
// Display current time and date information.

System.out.print("Date: ");
System.out.print(gcalendar.get(Calendar.MONTH)+1);
//System.out.print(Calendar.MONTH);
System.out.print(" " + gcalendar.get(Calendar.DATE) + " ");
System.out.println(year = gcalendar.get(Calendar.YEAR));

System.out.print("Time: ");
System.out.print(gcalendar.get(Calendar.HOUR_OF_DAY) + ":");
//System.out.print(Calendar.HOUR + ":");
System.out.print(gcalendar.get(Calendar.MINUTE) + ":");
System.out.println(gcalendar.get(Calendar.SECOND));

i want to use joda timing ... what should i do..

1

There are 1 best solutions below

0
On

You haven't stated in which case you would use the Joda-Time library, but the basics are stated in the website.

Here you can refer also to how to use the Joda-Time Chronology, one of the key concepts behind the library (which I highly recommend to read to grasp the basics). Here down a sample using the Gregorian calendar:

DateTimeZone zone = DateTimeZone.forID("Europe/London");
Chronology gregorian= GregorianChronology.getInstance(zone);

// current time with gregorian chronology
DateTime dt = new DateTime(gregorian);

int month = dt.getMonthOfYear(); // gets the current gregorian month
int year = dt.getYear();   // gets the current gregorian year
int day = dt.getDayOfMonth() // gets the current gregorian day
// ...