Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

I want to convert the timestamp to date format like 1382086394000 to 2013-10-18 08:53:14 using JavaScript function, currently I am using this function:

function cleanDate(d) {return new Date(+d.replace(/\/Date\((\d+)\)\//, '$1'));}

Can anyone help me with this?

1 Answer

0 votes
by (26.7k points)

Basically, you can multiple the data method by 1000 and then add other entities individually like years, months, etc. You can see the below example:

convertStampDate(unixtimestamp){

// Unixtimestamp

// Months array

var months_arr = ['January','February','March','April','May','June','July','August','September','October','November','December'];

// Convert timestamp to milliseconds

var date = new Date(unixtimestamp*1000);

// Year

var year = date.getFullYear();

// Month

var month = months_arr[date.getMonth()];

// Day

var day = date.getDate();

// Hours

var hours = date.getHours();

// Minutes

var minutes = "0" + date.getMinutes();

// Seconds

var seconds = "0" + date.getSeconds();

// Display date time in MM-dd-yyyy h:m:s format

var fulldate = month+' '+day+'-'+year+' '+hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);

// filtered fate

var convdataTime = month+' '+day;

return convdataTime;

}

After that, you can call the stamp argument.

I hope this will help.

Want to become a Java expert? join Java Certification now!!

Related questions

0 votes
1 answer
asked Apr 1, 2021 in Web Technology by Jake (7k points)
0 votes
1 answer
asked Jan 28, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
asked Jan 28, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer
0 votes
1 answer
asked Feb 14, 2021 in Java by dante07 (13.1k points)

Browse Categories

...