前台获取当前时间

  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 now = new Date();

       

        var year = now.getFullYear();       //年

        var month = now.getMonth() + 1;     //月

        var day = now.getDate();            //日

       

        var hh = now.getHours();            //时

        var mm = now.getMinutes();          //分

        var ss = now.getSeconds();           //秒

       

        var clock = year + "-";

  // if判断:   

        if(month < 10)

            clock += "0";

       

        clock += month + "-";

       

        if(day < 10)

            clock += "0";

           

        clock += day + " ";

       

        if(hh < 10)

            clock += "0";

           

        clock += hh + ":";

        if (mm < 10) clock += ‘0‘

        clock += mm + ":"

        

        if (ss < 10) clock += ‘0‘

        clock += ss; 

        alert(clock);

  --------------------------------------------------------------------------------------------------------------------

 //三目判断:

       var clock = year + "-"
                  + (month<10?"0"+month:month)
                  + "-"+(day<10?"0"+day:day)
                  + " "+(hh<10?"0"+hh:hh)
                  + ":"+(mm<10?"0"+mm:mm)
                  + ":"+(ss<10?"0"+ss:ss);

原文地址:https://www.cnblogs.com/ggq-insist-qiang/p/10294109.html

时间: 2024-07-29 01:36:05

前台获取当前时间的相关文章

easy UI mybatis springMvc 通过前台输入的时间查询数据库 Oracle

数据库类型为 date类型 实际值 如:2017/7/11 14:24:19 解决思路 前台UI的时间到后天是字符串 不转换 直接在Mybatis中接收时间字符串 前台UI代码 easy ui 时间控件 <td>上传日期:</td> <td> <input class="easyui-datebox" id="createTimeQ" name="createTime" data-options=&quo

js获取当前时间(昨天、今天、明天)

1.开发过程中某些前台页面的时间控件我们需要给默认当前时间,jquery可以轻松的帮我们实现,代码如下: //昨天的时间 var day1 = new Date(); day1.setTime(day1.getTime()-24*60*60*1000); var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate(); //今天的时间 var day2 = new Date()

[DBW]js获取当前时间(昨天、今天、明天)

开发过程中某些前台页面的时间控件我们需要给默认当前时间,jquery可以轻松的帮我们实现,代码如下 1 //昨天的时间 2 var day1 = new Date(); 3 day1.setTime(day1.getTime()-24*60*60*1000); 4 var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate(); 5 //今天的时间 6 var day2 = n

MySQL时间函数-获取当前时间-时间差

MySQL中获取当前时间为now(),不同于sqlserver getdate(). SQLServer转MySQL除变化top 1 -> limit 1之后报错: select 1 from record_visitor where visitor_ip='' and datediff(mi,visitor_time,getdate())<=30 limit 1 [Err] 1582 - Incorrect parameter count in the call to native func

iOS 获取当前时间以及计算年龄(时间差)

获取当前时间 NSDate *now = [NSDate date]; NSLog(@"now date is: %@", now); NSCalendar *calendar = [NSCalendar currentCalendar]; NSUInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarU

Js获取当前日期时间+日期印证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天

Js获取当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+JS判断某年某月有多少天 字符串转日期型+Js当前日期时间+日期验证+判断闰年+日期的天数差+日期格式化+日期所在年的第几周 日期时间脚本库方法列表Date.prototype.isLeapYear 判断闰年Date.prototype.Format 日期格式化Date.prototype.DateAdd 日期计算Date.prototype.DateDiff 比较日期差Date.prototype.toString 日期转字符

Javascript获取服务器时间

Javascript是运行在客户端的脚本,我们一般都用new Date()来获取当前时间,但是得到的是客户端的时间,客户端时间是随意更改的,如果要做一个产品发布倒计时的话,客户端时间一改,就要闹笑话了.业务中需要用到服务器时间的场景还有很多,那么仅仅通过js怎么拿到服务器时间呢?事实上,只需要一个ajax请求就搞定,通过读取XMLHttpRequest对象的请求头里面的时间戳得到当前服务器时间! 原理就是这么简单:通过ajax向服务器发送请求,当服务器收到请求后即可读取请求头的时间戳了,不管请求

PHP获取当前时间、时间戳的各种格式写法汇总

今天写下php中,如何通过各种方法 获取当前系统时间.时间戳,并备注各种格式的含义,可灵活变通.1.获取当前时间方法date()很简单,这就是获取时间的方法,格式为:date($format, $timestamp),format为格式.timestamp为时间戳–可填参数.2.获取时间戳方法time().strtotime()这两个方法,都可以获取php中unix时间戳,time()为直接获取得到,strtotime($time, $now)为将时间格式转为时间戳,$time为必填.清楚了这个

javascript获取当前时间

? //时间设置 <script type="text/javascript"> <!-- var myDate = new Date();     myDate.getYear();      //获取当前年份(2位)     myDate.getFullYear(); //获取完整的年份(4位,1970-????)     myDate.getMonth();      //获取当前月份(0-11,0代表1月)     myDate.getDate();