Convert Unix timestamp to readable date and vice versa

Paste your value in the field below:

How to convert unix time to date in javascript

To convert you need create new Date object and pass unixtime to constructor.

// Create a new JavaScript Date object based on the timestamp
// multiplied by 1000 because the argument is in milliseconds, not seconds.
var date = new Date(unix_timestamp*1000);

For getting the current unix time stamp you need extract it from the Date class:

var unixTime =;

Best way to get timestamp from any datetime:

var customDate = new Date(year, month, date, hours, minutes, seconds, ms);
var unixTime = customDate.getTime()/1000;

Unixtime in PHP

Getting current unix time:

$unixTime = time();
// or
$unixTime = strtotime('now');
// or
$now = new DateTime();
$unixTime = $now->getTimestamp();

For format unixtime to human readable date you have two ways: use date() function or DateTime object.

$date = date('d-m-Y H:i:s');
// or
$date = new DateTime();
echo $date->format('d-m-Y H:i:s');

Unixtime in MySQL

Example of query for getting current unix time stamp value:


Also you can format date time field to timestamp:

SELECT UNIX_TIMESTAMP(`timestamp_field`);
// or
SELECT UNIX_TIMESTAMP('yyyy-mm-dd h:i:s');

If you have some field with unixtime, you can get readable value by FROM_UNIXTIME() function

// getting date in custom fromat
SELECT FROM_UNIXTIME(unix_timestamp, , '%Y %D %M %h:%i:%s %x');

Unixtime in Python

The easiest way to get current time stamp:

import time
timestamp = int(time.time())

Convert date to unixtime:

import time
import datetime
dateTime =,1,5)

unixtime = time.mktime(dateTime.timetuple())
// or

Format unixtime stamp to human readable date:

import datetime
date = datetime.datetime.fromtimestamp(customTimestamp)
print(date.strftime('%Y-%m-%d %H:%M:%S'))

Unixtime in Java

Current time stamp:

long unixTime = System.currentTimeMillis() / 1000L;

// or
long unixTime =;

// getting time stamp from custom date
long unixTime = customDate.getTime() / 1000;

Convert date to unixtime:

import time
Date date = new Date(unixSeconds*1000L); // convert seconds to milliseconds
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z"); // the format of your date
String formattedDate = dateFormat.format(date);