Date format in aem | Community
Skip to main content
Adobe Employee
June 29, 2021
Solved

Date format in aem

  • June 29, 2021
  • 3 replies
  • 3626 views

How to get current date in this date format "2021-05-19T18:27:16.944+05:30" in Java script or Java?

I checked but all were in this format "2021-06-29T04:37:27.796Z". Can anyone tell me what should be format?

 

Thank you

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Dipti_Chauhan

Did you try java.time.OffsetDateTime ?

you can refer this code snippet

 

public static void main(String[] args) { String strDateTime = "Tue Jun 29 15:37:43 GMT+05:30 2021"; DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("E MMM d H:m:s O u", Locale.ENGLISH); OffsetDateTime formatedDate= OffsetDateTime.parse(strDateTime, dtfInput); System.out.println(formatedDate); }

 

3 replies

Asutosh_Jena_
Community Advisor
Community Advisor
June 29, 2021

Hi @keerthana_h_n 

 

Please see the link here:

https://github.com/adobe/htl-spec/blob/master/SPECIFICATION.md#1222-dates

 

${'yyyy-MM-dd HH:mm:ss.SSSXXX' @ format=properties.date, timezone='GMT+05:30'}

 

Thanks!

Dipti_Chauhan
Community Advisor
Dipti_ChauhanCommunity AdvisorAccepted solution
Community Advisor
June 29, 2021

Did you try java.time.OffsetDateTime ?

you can refer this code snippet

 

public static void main(String[] args) { String strDateTime = "Tue Jun 29 15:37:43 GMT+05:30 2021"; DateTimeFormatter dtfInput = DateTimeFormatter.ofPattern("E MMM d H:m:s O u", Locale.ENGLISH); OffsetDateTime formatedDate= OffsetDateTime.parse(strDateTime, dtfInput); System.out.println(formatedDate); }

 

Ritesh_Mittal
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
June 29, 2021

Hi @keerthana_h_n ,

 

You can use below code-

 

 

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class MyDateExample {

public static void main(String[] args) {
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z", Locale.getDefault());
     sdf.format(new Date());
     System.out.println("sdf"+sdf.format(new Date()));
}

}

 

 

Result - 2021-06-29T11:39:25 +0530