代码如下:
<script language="javascript"> /** * js日期时间与毫秒的转换 * site www.jb200.com */ function c1(){ var d = document.getElementsByName("s")[0].value; var b = (new Date(d)).getTime(); document.getElementsByName("s")[0].value = b; } function c2(){ var d = document.getElementsByName("d")[0].value; var b = new Date(d); b.setTime(d); document.getElementsByName("d")[0].value = b; } </script>
调用示例:
转换为毫秒:<input name="s" value=""><input type="button" onclick="c1()" value="ssss" >
转换为日期:<input name="d" value=""><input type="button" onclick="c2()" value="dddd" >