05-03-2021 04:20 AM
Hi All,
i want to parse created date to time format but it is throwing error.
my created date of document is:-
Mon May 03 11:58:44 BST 2021
i am trying to parse this into date format but it is throwing error:-
String createdDate = props.get(ContentModel.PROP_CREATED).toString(); Date date = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(createdDate);
i want output as:- 2021-05-03 11:58:44 for the created date.
Can someone guide how i can acheive it.
Thanks,
Piyush
05-03-2021 08:44 AM
This is not a question related to alfresco specifically and rather a simple java date format stuff, you could search google and do some research on this instead.
Since you have asked, this is the input date format that you get from properties: "EEE MMM d HH:mm:ss Z yyyy"
This is the output format you are looking for: "yyyy-MM-dd'T'HH:mm:ss.SSS"
So for your input "Mon May 03 11:58:44 BST 2021" date the output would be: "2021-05-03T06:58:44.000" as per the output format you have mentioned.
This is the sample code :
final DateFormat dateFormatsrc=new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy"); final Date sourceDate = (Date) dateFormatSrc.parse("Mon May 03 11:58:44 BST 2021"); final DateFormat dateFormatTarget = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); final String outputDate = dateFormatTarget.format(sourceDate);
System.out.println("Output: "+ outputDate);
Output: 2021-05-03T06:58:44.000
05-03-2021 08:44 AM
This is not a question related to alfresco specifically and rather a simple java date format stuff, you could search google and do some research on this instead.
Since you have asked, this is the input date format that you get from properties: "EEE MMM d HH:mm:ss Z yyyy"
This is the output format you are looking for: "yyyy-MM-dd'T'HH:mm:ss.SSS"
So for your input "Mon May 03 11:58:44 BST 2021" date the output would be: "2021-05-03T06:58:44.000" as per the output format you have mentioned.
This is the sample code :
final DateFormat dateFormatsrc=new SimpleDateFormat("EEE MMM d HH:mm:ss Z yyyy"); final Date sourceDate = (Date) dateFormatSrc.parse("Mon May 03 11:58:44 BST 2021"); final DateFormat dateFormatTarget = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); final String outputDate = dateFormatTarget.format(sourceDate);
System.out.println("Output: "+ outputDate);
Output: 2021-05-03T06:58:44.000
Explore our Alfresco products with the links below. Use labels to filter content by product module.