30 April, 2015

How to print time from java date using jodatime library ?

package com.javadevelopersguide;

import java.util.Date;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

public class FormatJavaDateJoda {

/**
* Get Time from Java Date
*/
public static void main(String[] args) {
Date date=new Date();
System.out.println("Before Formatting:::::::::"+date);
DateTimeFormatter format=DateTimeFormat.forPattern("hh:mm:ss a");
String time=format.print(new DateTime(date));
System.out.println("After Formatting::::::::::"+time);
}

}


Output :- 

Before Formatting:::::::::Thu Apr 30 21:52:19 EST 2015
After Formatting::::::::::09:52:19 PM

Find more jodatime format from site.




No comments:

Post a Comment