mozilla
您的搜索结果

    Date

    此页面上有脚本错误。虽然它是写给网站编辑,您可以在下面查看部分内容。

    摘要

    创建Date 实例用来处理日期和时间。

    语法

    new Date()
    new Date(毫秒)
    new Date(日期字符串)
    new Date(, , [, , , , 毫秒 ])

    参数

    毫秒
    代表自世界协调时1970年1月1日00:00:00开始的数值。
    日期字符串
     表示日期字符串。此字符串应该是parse方法中识别的格式
    代表年份的整数值。为了避免2000年问题最好指定4位数的年份; 使用 1998, 而不要用 98.
    代表月份的整数值从0(1月)到11(12月)。
    date
    代表一个月中的第几天的整数值,从1开始。
    hour
    代表一天中的小时数的整数值 (24小时制)。
    minute
    分钟数。
    second
    秒数。
    millisecond
    毫秒。表示毫秒时间阅读

    描述

    如果没有指定参数, the constructor creates a Date object for today's date and time according to local time. If you supply some arguments but not others, the missing arguments are set to 0. If you supply any arguments, you must supply at least the year, month, and day. You can omit the hours, minutes, seconds, and milliseconds.

    The date is measured in milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.

    The Date object provides uniform behavior across platforms.

    The Date object supports a number of UTC (universal) methods, as well as local time methods. UTC, also known as Greenwich Mean Time (GMT), refers to the time as set by the World Time Standard. The local time is the time known to the computer where JavaScript is executed.

    Invoking Date in a non-constructor context (i.e., without the new operator) will return a string representing the current time.

    属性

    For properties available on Date instances, see Properties of Date instances.

    prototype
    允许为Date增加额外的属性。

    Properties inherited from Function.prototype

    Methods

    For methods available on Date instances, see Methods of Date instances.

    now
    Returns the numeric value corresponding to the current time.
    parse
    Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00, local time.
    UTC
    Accepts the same parameters as the longest form of the constructor, and returns the number of milliseconds in a Date object since January 1, 1970, 00:00:00, universal time.

    Methods inherited from Function.prototype

    Date instances

    {{ :cn/Core_JavaScript_1.5_Reference/Global_Objects/Date/prototype }}

    例子

    Example: Several ways to assign dates

    The following examples show several ways to assign dates:

    today = new Date();
    birthday = new Date("December 17, 1995 03:24:00");
    birthday = new Date(1995,11,17);
    birthday = new Date(1995,11,17,3,24,0);
    

    Example: Calculating elapsed time

    The following examples show how to determine the elapsed time between two dates:

    // using static methods
    var start = Date.now();
    // the event you'd like to time goes here:
    doSomethingForALongTime();
    var end = Date.now();
    var elapsed = end - start; // time in milliseconds
    
    // if you have Date objects
    var start = new Date();
    // the event you'd like to time goes here:
    doSomethingForALongTime();
    var end = new Date();
    var elapsed = end.getTime() - start.getTime(); // time in milliseconds
    

    文档标签和贡献者

    Contributors to this page: ziyunfei
    最后编辑者: ziyunfei,