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

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

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?


1 Reply


Community Advisor

hi @nikita24tailor 

You may have to write custom java logic to render the date format as per your requirement :


Similar discussion :


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?


Community Advisor
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!