활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
활동이 없어 이 대화는 잠겼습니다. 새 게시물을 작성해 주세요.
I am getting created date of the pages in aem using query builder through a servlet. But the output date is in UNIX format. I want to render the date in correct date format like Jan 14, 2022. Is there a way I can change this using VueJS. Or any other to do this?
조회 수
답글
좋아요 수
You may have to write custom java logic to render the date format as per your requirement :
Similar discussion : https://experienceleaguecommunities.adobe.com/t5/adobe-experience-manager/aem-query-debugger-date-fo...
I tried doing that using the following code:
String text = props.get("jcr:created").toString(); long timeStamp = Long.parseLong(text); //convert seconds to milliseconds Date date = new Date(timeStamp); // format of the date SimpleDateFormat jdf = new SimpleDateFormat("dd MMM yyyy"); String java_date = jdf.format(date); System.out.println("Created Date: "+java_date);
But the problem is jcr:created returns an object which has the following values:
java.util.GregorianCalendar[time=1654598024706,areFieldsSet=true,areAllFieldsSet=true,lenient=false,zone=sun.util.calendar.ZoneInfo[id="GMT+05:30",offset=19800000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2022,MONTH=5,WEEK_OF_YEAR=24,WEEK_OF_MONTH=2,DAY_OF_MONTH=7,DAY_OF_YEAR=158,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=4,HOUR_OF_DAY=16,MINUTE=3,SECOND=44,MILLISECOND=706,ZONE_OFFSET=19800000,DST_OFFSET=0]
But I only want the timestamp. Is there a way that I can get only the timestamp from jcr:created?
import moment from 'moment'; Vue.filter('formatDate', function(value) { if (value) { return moment(String(value)).format('MM/DD/YYYY hh:mm') } });
Here is the sample code, you can use for converting to a different format.
The value of the date is returned through a servlet as json data. How can I use this code for the same?
Hi @nikita24tailor ,
Try this statement
vueJSdate = new Date(unixTimestamp * 1000);
Timestamps of UNIX will be in seconds and Date() required in milliseconds.
Found similar issue here: https://stackoverflow.com/questions/72643134/convert-unix-timestamp-to-date-using-vuejs
Hope that helps!
Regards,
Santosh
조회 수
Likes
답글