Date format in aem

Avatar

Avatar
Ignite 1
Level 2
keerthana_hn
Level 2

Likes

7 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Boost 5
Boost 3
Boost 1
Validate 1
View profile

Avatar
Ignite 1
Level 2
keerthana_hn
Level 2

Likes

7 likes

Total Posts

32 posts

Correct reply

0 solutions
Top badges earned
Ignite 1
Boost 5
Boost 3
Boost 1
Validate 1
View profile
keerthana_hn
Level 2

28-06-2021

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

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile

Avatar
Boost 100
Level 6
Dipti_Chauhan
Level 6

Likes

126 likes

Total Posts

144 posts

Correct reply

41 solutions
Top badges earned
Boost 100
Give Back 10
Affirm 25
Boost 50
Boost 25
View profile
Dipti_Chauhan
Level 6

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

    }

 

Answers (2)

Answers (2)

Avatar

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile

Avatar
Boost 5
Level 7
Ritesh_M
Level 7

Likes

179 likes

Total Posts

142 posts

Correct reply

45 solutions
Top badges earned
Boost 5
Boost 3
Boost 1
Applaud 5
Affirm 1
View profile
Ritesh_M
Level 7

28-06-2021

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

Avatar

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

594 likes

Total Posts

705 posts

Correct reply

208 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile

Avatar
Applaud 25
Level 10
asutosh_jena
Level 10

Likes

594 likes

Total Posts

705 posts

Correct reply

208 solutions
Top badges earned
Applaud 25
Give Back 100
Boost 500
Affirm 100
Ignite 1
View profile
asutosh_jena
Level 10

28-06-2021

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!