Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Date format in aem

keerthana_hn
Level 3
Level 3

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

1 Accepted Solution
Dipti_Chauhan
Correct answer by
Community Advisor
Community Advisor

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);

    }

 

View solution in original post

0 Replies
asutosh_jena
Community Advisor
Community Advisor

Hi @keerthana_hn 

 

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
Correct answer by
Community Advisor
Community Advisor

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);

    }

 

View solution in original post

Ritesh_M
Community Advisor
Community Advisor

Hi @keerthana_hn ,

 

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