How to convert date in eventDate to desired format | Community
Skip to main content
Level 2
Jan 13, 2023 11:36 AM UTC
Solved

How to convert date in eventDate to desired format

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.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
arunpatidar
arunpatidarAccepted solution
New Participant
Jan 13, 2023 2:27 PM UTC

you can do this for Calendar type as well.

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

4 replies

Manu_Mathew_
New Participant
Jan 13, 2023 1:46 PM UTC

@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.

Translate
arunpatidar
New Participant
Jan 13, 2023 1:27 PM UTC

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

Translate
Arun Patidar
Magicr
Level 6
Jan 13, 2023 1:45 PM UTC

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.

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Jan 13, 2023 2:27 PM UTC

you can do this for Calendar type as well.

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