I have been working in AEM for some time now and I have encountered quite a few time formats that can be used to parse date when writing backend code in Java. We generally use SimpleDateFormat to do this.
------------------------------------------------------------------------------------
Format Example
------------------------------------------------------------------------------------
yyyy-MM-dd'T'HH:mm:ss.SS 2015-07-29T21:32:58.89
yyyy-MM-dd'T'HH:mm:ss.SSSXXX 2016-02-18T07:35:13.014-05:00
yyyy-MM-dd'T'HH.mm.ss.SSSX 2016-02-22T00.39.30.376-05.00
------------------------------------------------------------------------------------
This can be used in the following way
package samples.codermag.net;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TimeTesterClass {
public static void main(String[] args) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
Date date = format.parse("2016-02-18T07:35:13.014-05:00");
System.out.println(date.toString());
} catch (ParseException e) {}
}
}
No comments:
Post a Comment
If you have any doubts or questions, please let us know.