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
Solved! Go to Solution.
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
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
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.