javascript date to unix timestamp – Convert normal date to unix timestamp

javascript date to unix timestamp To get the unix timestamp using JavaScript you need to use the getTime() function of the build in Date object.

javascript date to unix timestamp

Math.round(new Date().getTime() / 1000).toString() – A Number representing the milliseconds elapsed since the UNIX epoch. The Javascript Date object has a number of functions for working with dates and times.

new Date('2021.08.10').getTime() / 1000

javasctipt unix timestamp from date

Math.round(new Date().getTime() / 1000).toString()

Convert Unix timestamp to Date time with JavaScript

function convert(){

 var unixtimestamp = document.getElementById('timestamp').value;

 var months_arr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

 var join_at = new Date(unixtimestamp*1000);

 var year = join_at.getFullYear();

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

 var day = join_at.getDate();

 var hours = join_at.getHours();

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

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

 var convdataTime = month+'-'+day+'-'+year+' '+hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
 document.getElementById('datetime').innerHTML = convdataTime;

javascript date convert to unix

new Date('2021.08.10').getTime() / 1000

don’t Miss : Convert Date To Timestamp Javascript

I hope you get an idea about javascript date to unix timestamp.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment