25
2020
04

JS获取当前日期

date对象的方法

date 对象能够使你获得相对于国际标准时间(格林威治标准时间,现在被称为 utc-universal coordinated time)或者是 flash 播放器正运行的操作系统的时间和日期。要使用date对象的方法,你就必须先创建一个date对象的实体(instance)。

date 对象必须使用 flash 5 或以后版本的播放器。 

date 对象的方法并不是静态的,但是在使用时却可以应用于所指定的单独实体。

<SCRIPT LANGUAGE="javascript">
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( );        //获取日期与时间
if (mytime<"23:30:00")
{
alert(mytime);
}
</SCRIPT>

日期时间脚本库方法列表

Date.prototype.isLeapYear 判断闰年

Date.prototype.Format 日期格式化

Date.prototype.DateAdd 日期计算

Date.prototype.DateDiff 比较日期差

Date.prototype.toString 日期转字符串

Date.prototype.toArray 日期分割为数组

Date.prototype.DatePart 取日期的部分信息

Date.prototype.MaxDayOfDate 取日期所在月的最大天数

Date.prototype.WeekNumOfYear 判断日期所在年的第几周

StringToDate 字符串转日期型

IsValidDate 验证日期有效性

CheckDateTime 完整日期时间检查

daysBetween 日期天数差

原文链接:https://www.qiquanji.com/post/7819.html

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

微信扫码关注

更新实时通知

« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。