Convert Unix timestamp to readable date and vice versa

Paste your value in the field below:
::
X

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 = Date.now;

Best way to get timestamp from any datetime:

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

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();
$date->setTimestamp($timeStamp);
echo $date->format('d-m-Y H:i:s');
X

Unixtime in MySQL

Example of query for getting current unix time stamp value:

SELECT UNIX_TIMESTAMP();

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

SELECT FROM_UNIXTIME(unixtime);
// getting date in custom fromat
SELECT FROM_UNIXTIME(unix_timestamp, , '%Y %D %M %h:%i:%s %x');
        
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 = datetime.date(2015,1,5)

unixtime = time.mktime(dateTime.timetuple())
...
// or
int(dateTime.strftime("%s"))
        

Format unixtime stamp to human readable date:

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

Unixtime in Java

Current time stamp:

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

// or
long unixTime = Instant.now().getEpochSecond();

// 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);
System.out.println(formattedDate);