JS 日期与时间戮相互转化的简单实例

时间:2016-06-22    点击:100   

1、日期格式转时间戮 

function getTimestamp(time) 
 {
   return Date.parse(new Date(time));
 }

2、时间戮转日期格式 

function transformPHPTime(time) 
{
    var date = new Date(time * 1000);
    
    Y = date.getFullYear() + '-';
    M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
    D = date.getDate() + ' ';
    h = date.getHours() + ':';
    m = date.getMinutes() + ':';
    s = date.getSeconds();

    return Y+M+D+h+m+s;
}

以上就是小编为大家带来的JS 日期与时间戮相互转化的简单实例全部内容了,希望大家多多支持本站~

JavaScript中获取HTML元素值的三种方法
js 获取经纬度的实现方法
Json解析的方法小结
JS产生随机数的几个用法详解
javascript时间戳和日期字符串相互转换代码(超简单)
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved