Convert Unix timestamp to DateTime jQuery And JS

To Convert Unix timestamp to DateTime using jQuery and JS, we use the JavaScript date object and other date functions to get the time and date with months.

Here are 4 steps to convert timestamp to DateTime using jQuery and JS,

  1. Convert timestamp to milliseconds.
  2. Place the milisecond value as argument in the date object.
  3. By using toLocaleString() function, we convert it to the human readable date format.

Live Example of Convert Unix timestamp to DateTime jQuery

In the below example, we create a paragraph with an ID attribute to print the date.

Then we assign a timestamp value to a variable, we convert the timestamp to milliseconds by multiplying with 1000.

Now we pass the values as an argument to the JS Date object which helps to convert.

At last, JavaScript converts Unix timestamp to yyyy-mm-dd by using toLocaleString() function.

See the Pen Convert Unix timestamp to DateTime jQuery by Bikash Panda (@phpcodertech) on CodePen.

Also Read: How to Get Current Date and Time In JavaScript

Convert Unix timestamp to DateTime with Month name Using JavaScript

Live View

Also Read: Get PHP Date Time Difference in Days, Hours, Minutes, and Seconds

See the Pen Convert Unix timestamp to datetime with month name jQuery by Bikash Panda (@phpcodertech) on CodePen.

Code Highlights:

HTML: we create an input box where we put Unix timestamp value. Then we create an HTML button where we call our JavaScript function.

SCRIPT: In the JS script, we create a function named unixToDatetime().

Take the input box value by using the input box’s ID attribute and JS getElementById function.

We create an array with the month name to print the date with the month name. Now we convert the timestamp to milisecond.

By using the JS date object we get the year, month, and date-time. At last we concatenate and get the complete date time with the month name.

Please let me know if you are facing any issues.

Also Read: PHP Timestamp to Date Readable Format With Example

Happy Coding..!

Was this article helpful?
YesNo
My name is Bikash Kr. Panda. I own and operate PHPCODER.TECH. I am a web Programmer by profession and working on more than 50 projects to date. Currently I am working on the web-based project and all the CMS and frameworks which are based on PHP.
Posts created 188

Leave a Reply

Your email address will not be published.

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top