zoukankan      html  css  js  c++  java
  • Js获取当前日期时间

    Js获取当前日期时间
    var myDate = new Date();
    myDate.getYear();        //获取当前年份(2位)
    myDate.getFullYear();    //获取完整的年份(4位,1970-????)
    myDate.getMonth();       //获取当前月份(0-11,0代表1月)
    myDate.getDate();        //获取当前日(1-31)
    myDate.getDay();         //获取当前星期X(0-6,0代表星期天)
    myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)
    myDate.getHours();       //获取当前小时数(0-23)
    myDate.getMinutes();     //获取当前分钟数(0-59)
    myDate.getSeconds();     //获取当前秒数(0-59)
    myDate.getMilliseconds();    //获取当前毫秒数(0-999)
    myDate.toLocaleDateString();     //获取当前日期
    var mytime=myDate.toLocaleTimeString();     //获取当前时间
    myDate.toLocaleString( );        //获取日期与时间
    //当月天数
    var curMonthDays = new Date(myDate.getFullYear(), (myDate.getMonth()+1), 0).getDate();
    */
    当月天数
    var curMonthDays = new Date(myDate.getFullYear(), (myDate.getMonth()+1), 0).getDate();
    通过JQ生成年月日下拉框数据,支持定位功能
    jS部分:
    var year = 2005;
    var month = 12;
    var day = 20;
    {literal}
    $(document).ready(function(){
    set_date_select(year,month,day);
    $(’#month’).change(function(){
    var tmp_year = $(”#year”).val();
    var tmp_month = $(”#month”).val();
    set_date_select(tmp_year,tmp_month,0);
    });
    });
    function set_date_select(year,month,day){
    $(”#year”).empty();
    $(”#month”).empty();
    $(”#day”).empty();
    //年
    var myDate = new Date();
    var year_num = myDate.getFullYear()-1900+1;
    for(var i=0;i<year_num;i++){
    var tmp_year = 1900+i;
    if(tmp_year == year )
    $(’#year’).append(”<option value=’”+tmp_year+”‘ selected=’selected’>”+tmp_year+”</option>”);
    else
    $(’#year’).append(”<option value=’”+tmp_year+”‘>”+tmp_year+”</option>”);
    }
    //月
    for(var i=1;i<=12;i++){
    if(i == month)
    $(’#month’).append(”<option value=’”+i+”‘ selected=’selected’>”+i+”</option>”);
    else
    $(’#month’).append(”<option value=’”+i+”‘>”+i+”</option>”);
    }
    //当月天数
    var curMonthDays = 31;
    if(month > 0 && month <= 12){
    var curMonthDays = new Date(myDate.getFullYear(), ( month ), 0).getDate();
    }
    //日
    for(var i=1;i<=curMonthDays;i++){
    if(i == day)
    $(’#day’).append(”<option value=’”+i+”‘ selected=’selected’>”+i+”</option>”);
    else
    $(’#day’).append(”<option value=’”+i+”‘ >”+i+”</option>”);
    }
    }
    HTML部分:
    <select name=”year” id=”year”></select>
    <select name=”month” id=”month”></select>
    <select name=”day” id=”day”></select>
    

      

  • 相关阅读:
    揭开Socket编程的面纱(留着自己慢慢看)
    XML 新手入门基础知识
    RocketMQ集群平滑下线或重启某个节点
    RocketMQ borker配置文件
    ES:在线迁移集群索引,数据不丢失
    SQL命令汇总
    Redis过期key淘汰策略
    中间件服务器内核参数优化
    在线做RAID命令
    CPU网卡亲和绑定
  • 原文地址:https://www.cnblogs.com/wqing/p/3981349.html
Copyright © 2011-2022 走看看