Expand my Community achievements bar.

Adobe Summit 2025: AEM Session Recordings Are Live! Missed a session or want to revisit your favorites? Watch the latest recordings now.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

SOLVED

How to convert date in eventDate to desired format

Avatar

Level 2

Hi All,

I have an eventList with eventDate property.  "eventDate":"Jan 25, 2023, 2:35:00 PM" I am getting this date, I want to convert this date to 25-January, 2023. I have tried many solutions but couldnt work out. please do help.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

you can do this for Calendar type as well.

Calendar cal = eventDate;
java.util.Date date = cal.getTime();
Arun Patidar

AEM LinksLinkedIn

View solution in original post

4 Replies

Avatar

Community Advisor

Hi,

Did you try using below format 

DateFor = new SimpleDateFormat("dd-MMMM,yyyy");

sampl code

public static void main(String[] args) {
    Date date = new Date();
    SimpleDateFormat DateFor = new SimpleDateFormat("dd-MMMM,yyyy");
    String stringDate = DateFor.format(date);
    System.out.println("Date Format with dd MMMM yyyy : "+stringDate);
  }

output:

Date Format with dd MMMM yyyy : 13-January,2023

Arun Patidar

AEM LinksLinkedIn

Avatar

Level 7

Uhm, the properties in AEM 6.x aren't an instance of java date. Although the CRX shows "Date" it is truly an instance of java calendar.

Avatar

Correct answer by
Community Advisor

you can do this for Calendar type as well.

Calendar cal = eventDate;
java.util.Date date = cal.getTime();
Arun Patidar

AEM LinksLinkedIn

Avatar

Community Advisor

@rolliedub 

SimpleDateFormat data = new SimpleDateFormat("dd-MMMM,yyyy");
String eventDate = "Jan 25, 2023, 2:35:00 PM";
Date date = new Date(eventDate);

String convert = data.format(date);
System.out.println("Date Format with dd MMMM yyyy : "+date);

output: 25-January, 2023.