I want to parse created date to date format

cancel
Showing results for 
Search instead for 
Did you mean: 
piyush48
Established Member

I want to parse created date to date format

Jump to solution

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

 

1 Solution

Accepted Solutions
abhinavmishra14
Advanced

Re: I want to parse created date to date format

Jump 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

 

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)

View solution in original post

1 Reply
abhinavmishra14
Advanced

Re: I want to parse created date to date format

Jump 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

 

 

 

~Abhinav
(ACSCE, AWS SAA, Azure Admin)