zoukankan      html  css  js  c++  java
  • js 日期转换 strToDate

    //定义日期字符串
    var myStartStr = “2015-05-04 17:10:10” 
    var myEndStr = “2015-05-04 17:10:10” 
    var myStartDate = new Date(Date.parse(myStartStr.replace(/-/g, "/"))); 
    var myEndDate = new Date(Date.parse(myEndStr.replace(/-/g, "/"))); 
    //js判断日期范围
    var currDate = new Date();
    if(currDate<myStartDate||curr_date>myEndDate){
    				alert("预约的时间不得超过有效期的范围");
    				return;
    			}
    //日期的操作: 
    myStrDate.getYear();        //获取当前年份(2位) 
    myStrDate.getFullYear();    //获取完整的年份(4位,1970-????) 
    myStrDate.getMonth();       //获取当前月份(0-11,0代表1月) 
    myStrDate.getDate();        //获取当前日(1-31) 
    myStrDate.getDay();         //获取当前星期X(0-6,0代表星期天) 
    myStrDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数) 
    myStrDate.getHours();       //获取当前小时数(0-23) 
    myStrDate.getMinutes();     //获取当前分钟数(0-59) 
    myStrDate.getSeconds();     //获取当前秒数(0-59) 
    myStrDate.getMilliseconds();    //获取当前毫秒数(0-999) 
    myStrDate.toLocaleDateString();     //获取当前日期  2015/5/4
    var mytime=myStrDate .toLocaleTimeString();     //获取当前时间 下午5:10:47
    myStrDate .toLocaleString( );        //获取日期与时间  2015/5/4 下午5:10:47


  • 相关阅读:
    0626 Django模型(ORM)
    0625 Django 基础
    0530JavaScript基础2
    CentOS7.5安装cairo-dock,比mac托盘还美
    CentOS7.5安装与使用mysql-workbench
    CentOS7.6安装rime輸入法
    CentOS7.5 firefox Flash插件更新
    记一次ceph集群的严重故障
    ceph笔记(一)
    CentOS7.6打开的程序窗口居中
  • 原文地址:https://www.cnblogs.com/liubo6/p/4491114.html
Copyright © 2011-2022 走看看