Index
Find more epoch conversion routines (in other programming languages) on the homepage.VBScript / ASP routines
The current Unix time:
DateDiff("s", "01/01/1970 00:00:00", Now())
date2epoch converts a VBScript date to an Unix timestamp:
function date2epoch(myDate)
date2epoch = DateDiff("s", "01/01/1970 00:00:00", myDate)
end function
Usage example:
date2epoch(Now())
epoch2date converts Unix timestamps back to VBScript dates:
function epoch2date(myEpoch)
epoch2date = DateAdd("s", myEpoch, "01/01/1970 00:00:00")
end function
JavaScript routines
Convert an epoch to human readable date:
var myDate = new Date( your epoch date *1000); document.write(myDate.toGMTString()+"<br>"+myDate.toLocaleString());
The example above gives the following output (with epoch date 1):
You can also use getFullYear, getMonth, getDay etc. See documentation below.
Convert human readable dates to epoch:
var myDate = new Date("July 1, 1978 02:30:00"); // Your timezone!
var myEpoch = myDate.getTime()/1000.0;
document.write(myEpoch);
The example above gives the following output:
There are many ways to create dates in Javascript (for example with setFullYear, setMonth, setDay etc.).
For more information on the JavaScript Date object click here.
PHP routines
Convert a human readable date to epoch:
Use mktime:
// PHP 5.1+
date_default_timezone_set('UTC');
mktime ( $hour, $minute, $second, $month, $day, $year )
// before PHP 5.1
mktime ( $hour, $minute, $second, $month, $day, $year, $is_dst )
// $is_dst : 1 = daylight savings time (DST), 0 = no DST , -1 (default) = auto
If you are using PHP 5.1 or higher use date_default_timezone_set to set/overrule your timezone.
The PHP timezone handling takes care of daylight saving times (see a list of possible timezones).
time() returns the current epoch date.
Convert a epoch to human readable date:
Use the date function.
Example: Create an epoch date for 1/1/2000, convert it back and display it.
echo date("M/d/Y", mktime(0, 0, 0, 1, 1, 2000));
Comments and questions
blog comments powered by DisqusPages
HomeTools
Epoch converter
Batch converter
Epoch clock
Epoch list
Time zone converter
Programming
Routines by language
Epoch in PERL
Epoch in C
Epoch in MySQL
Epoch in VBScript/ASP/JavaScript/PHP
Date and Time
Calculate difference between two dates
Week numbers
Weeks by year
Day numbers
More
Comments & questions
Epoch Converter for Mobiles
Este sitio en Español
Related cookbooks
Unicode Tools
Character Set Tools