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

[AEM Gems Webinar] Accelerating Experience Manager as a Cloud Service development with Rapid Development Environments

Convert UNIX timestamp to date using Vue JS


Level 4

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?


5 Replies


Level 4

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:
But I only want the timestamp. Is there a way that I can get only the timestamp from jcr:created?


Level 8
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.


Level 4

The value of the date is returned through a servlet as json data. How can I use this code for the same?


Community Advisor

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:

Hope that helps!