Created
September 26, 2013 13:32
-
-
Save gmilby/6714229 to your computer and use it in GitHub Desktop.
convert unix time to human readable or vice versa
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> | |
<title></title> | |
<meta name="DESCRIPTION" content="Convert Unix time to a readable date"> | |
<meta name="KEYWORDS" content="unix, UT, GMT, seconds, epoch, milliseconds"> | |
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> | |
function timeToHuman() { | |
var theDate = new Date(document.u2h.timeStamp.value * 1000); | |
dateString = theDate.toGMTString(); | |
document.u2h.result.value = dateString; | |
} | |
function humanToTime() { | |
var humDate = new Date(Date.UTC(document.h2u.inYear.value, | |
(stripLeadingZeroes(document.h2u.inMon.value)-1), | |
stripLeadingZeroes(document.h2u.inDay.value), | |
stripLeadingZeroes(document.h2u.inHr.value), | |
stripLeadingZeroes(document.h2u.inMin.value), | |
stripLeadingZeroes(document.h2u.inSec.value))); | |
document.h2u.result.value = (humDate.getTime()/1000.0); | |
} | |
function stripLeadingZeroes(input) { | |
if((input.length > 1) && (input.substr(0,1) == "0")) { | |
return input.substr(1); | |
} else { | |
return input; | |
} | |
} | |
</script> | |
<script language="JavaScript" src="/misc_functions.js" type="text/javascript"></script> | |
</head> | |
<body> | |
<center> | |
<table border="0" cellpadding="1" cellspacing="0" width="692" id="mainbg"><tr><td> | |
<!-- The above table places the 1 pixel gray outline around the whole page --> | |
<table border="0" cellspacing="0" cellpadding="0" width="690"> | |
<tr> | |
<td width="500" valign="top"> | |
<table border="0" cellpadding="10" cellspacing="0" width="500"> | |
<tr> | |
<td width="500" valign="top" class="content"> | |
<div align="center"> | |
<span class="red">Unix Time Conversion</span> | |
</div> | |
<p> </p> | |
<form name="u2h"> | |
<center> | |
<table border=1><tr><td align="center"> | |
<p><font color="#000080"><font size="3"><b>Convert Unix timestamp to Readable Date/time</b><br></font> | |
<font size="2">(based on seconds since standard epoch of 1/1/1970)</font></font><br> | |
<font color="#800000" size="2">UNIX TimeStamp:</font> <input type="text" name="timeStamp" size="20"><br> | |
<input type="button" value="Submit" onClick="timeToHuman();"> <input type="reset" value="Reset"><br> | |
<input name="result" type="text" value="" size="30" READONLY> | |
</p> | |
</td></tr></table> | |
</center> | |
</form> | |
<form name="h2u"> | |
<center> | |
<table border="1"><tr><td> | |
<table border="0"> | |
<tr> | |
<td colspan="11" align="center"><p><font color="#000080"><font size="3"><b>Convert a Date/Time to a Unix timestamp</b><br></font> | |
<font size="2">(based on seconds since standard epoch of 1/1/1970)</font></font></td> | |
</tr> | |
<tr> | |
<th>Mon:</th> | |
<th> </th> | |
<th>Day:</th> | |
<th> </th> | |
<th>Year:</th> | |
<th> </th> | |
<th>Hr:</th> | |
<th> </th> | |
<th>Min:</th> | |
<th> </th> | |
<th>Sec:</th> | |
</tr> | |
<tr> | |
<td><input type="text" size="4" maxlength="2" name="inMon"></td> | |
<th>/</th> | |
<td><input type="text" size="4" maxlength="2" name="inDay"></td> | |
<th>/</th> | |
<td><input type="text" size="4" maxlength="4" name="inYear"></td> | |
<th>at</th> | |
<td><input type="text" size="4" maxlength="2" name="inHr"></td> | |
<th>:</th> | |
<td><input type="text" size="4" maxlength="2" name="inMin"></td> | |
<th>:</th> | |
<td><input type="text" size="4" maxlength="2" name="inSec"></td> | |
</tr> | |
<tr> | |
<td colspan="11" align="center"><input type="button" value="Submit" onClick="humanToTime();"> <input type="reset" value="Reset"></td> | |
</tr> | |
<tr> | |
<td colspan="11" align="center"><input name="result" type="text" value="" size="30" READONLY></td> | |
</tr> | |
</table> | |
</td></tr></table> | |
</center> | |
</form> | |
<!-- Center Bottom --> | |
</td></tr></table> | |
<!-- End Center Bottom --> | |
</td> | |
</tr> | |
</table> | |
</td> | |
<td width="1" bgcolor="#000000" valign="top"><img src="/spacer.gif" width="1" height="2" alt="" border="0"></td> | |
<td width="190" valign="top" class="rightside"> | |
<!-- Right side Start --> | |
<table width="100%" cellpadding="0" cellspacing="0" border="0"> | |
<tr> | |
<td align="center" id="rcontainer"></td> | |
</tr> | |
</table> | |
<div align="center"> | |
<table width="90%" cellpadding="0" cellspacing="0" border="0"> | |
<tr> | |
<td class="rightside" id="qlinks"><br> | |
</td> | |
</tr> | |
</table> | |
</div> | |
<!-- End Right Side Ads --> | |
<!-- Right side End --> | |
</td> | |
</tr> | |
<tr> | |
<td height="1" colspan="3"><img src="/black.gif" width="690" height="1" alt=""></td> | |
</tr> | |
</table> | |
<table border="0" cellpadding="5" cellspacing="0" width="690"> | |
<tr> | |
<td width="410" height="17" class="footer"> | |
</td> | |
<td width="250" height="17" align="right" class="footer"></td> | |
</tr> | |
</table> | |
</td> | |
</tr> | |
</table> | |
</center> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment