js中的New Date获取各种时间

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type="text/javascript">
        var thedate = new Date();
        //alert(thedate.toLocaleString());
        //alert(thedate);
          //alert('LocaleString:'+thedate.toLocaleString());//将时间转换成本地的字符串表示
//        alert('String:' + thedate.toString());
//        alert('LocaleDateString:' + thedate.toLocaleDateString());
//        alert('LocaleTimeString:' + thedate.toLocaleTimeString());
//        alert(thedate.toTimeString());
         alert('Date:' + thedate.getDate());
//        alert('Day:' + thedate.getDay());
          alert('Year:' + thedate.getFullYear());
          //alert('当前日期为' + thedate.getFullYear(), thedate.getMonth(), thedate.getDate(), thedate.getHours() + '时' + thedate.getMinutes() + '分' + thedate.getSeconds() + '秒');
//        alert('Milliseconds:' + thedate.getMilliseconds());
       // alert('Minutes:' + thedate.getMinutes()+'分');
//        alert('Month:' + (thedate.getMonth()+1));//如果用整数表示月份的话,0代表1月,1代表2月...11代表12月
        //alert('Seconds:' + thedate.getSeconds()+'秒');

        //var thedate = new Date(2012, 3, 7, 12, 11, 12,222);
//        alert(thedate.toLocaleString());
        //        alert(thedate.getMilliseconds());

        /*var thedate = new Date('2012, March, 7,12:11:22');
        alert(thedate.toLocaleString());
        alert(thedate.getMilliseconds());
        alert(thedate.getYear()); //建议使用GetFullYear获取年*/

        var thedate = new Date('2012, March, 7,12:11:22');
        thedate.setFullYear(2013);
        alert(thedate.toLocaleString());
        alert(thedate.toLocaleString());
        thedate.setFullYear(2013,3,8);
        alert(thedate.toLocaleString());
        thedate.setDate(1);
        alert(thedate.toLocaleString());
        thedate.setMonth(17);
        alert(thedate.toLocaleString());
        thedate.setDate(365);
        thedate.setDate(32);
        alert(thedate.toLocaleString());


    </script>
</head>
<body>

</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值