Date 的构造方法

new Date();
new Date(value);
new Date(dateString);
new Date(year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]]);
  • 无参数 : 取当前时间。
  • value : 相对于 “January 1, 1970, 00:00:00 UTC” 的毫秒。
  • dateString : 符合 IETF-compliant RFC 2822 timestamps 或 ISO 8601 Extended Format(es5开始支持),以及非标格式。
  • year, monthIndex [, day [, hours [, minutes [, seconds [, milliseconds]]]]] : 年月日时分秒

ISO 8601 Extended Format 示例

chrome console> console.log(new Date('2019-12-11T08:30:05+08:00'));
Wed Dec 11 2019 08:30:05 GMT+0800 (中国标准时间)
chrome console> console.log(new Date('2019-12-11T08:30:05'));
Wed Dec 11 2019 08:30:05 GMT+0800 (中国标准时间)
chrome console> console.log(new Date('2019-12-11T08:30:05+00:00'));
Wed Dec 11 2019 16:30:05 GMT+0800 (中国标准时间)
chrome console> console.log(new Date('2019-12-11T08:30:05Z'));
Wed Dec 11 2019 16:30:05 GMT+0800 (中国标准时间)

浏览器兼容

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#Browser_compatibility

参考

https://blog.csdn.net/beta_xiyan/article/details/76991635
https://segmentfault.com/a/1190000017579541
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

IETF-compliant RFC 2822 timestamps

Date and Time SpecificationDate and time occur in several header fields.  This section specifiesthe syntax for a full date and time specification.  Though foldingwhite space is permitted throughout the date-time specification, itis RECOMMENDED that a single space be used in each place that FWSappears (whether it is required or optional); some olderimplementations may not interpret other occurrences of folding whitespace correctly.date-time       =       [ day-of-week "," ] date FWS time [CFWS]day-of-week     =       ([FWS] day-name) / obs-day-of-weekday-name        =       "Mon" / "Tue" / "Wed" / "Thu" /"Fri" / "Sat" / "Sun"date            =       day month yearyear            =       4*DIGIT / obs-yearmonth           =       (FWS month-name FWS) / obs-monthmonth-name      =       "Jan" / "Feb" / "Mar" / "Apr" /"May" / "Jun" / "Jul" / "Aug" /"Sep" / "Oct" / "Nov" / "Dec"day             =       ([FWS] 1*2DIGIT) / obs-daytime            =       time-of-day FWS zonetime-of-day     =       hour ":" minute [ ":" second ]hour            =       2DIGIT / obs-hourminute          =       2DIGIT / obs-minutesecond          =       2DIGIT / obs-secondzone            =       (( "+" / "-" ) 4DIGIT) / obs-zoneThe day is the numeric day of the month.  The year is any numericyear 1900 or later.The time-of-day specifies the number of hours, minutes, andoptionally seconds since midnight of the date indicated.The date and time-of-day SHOULD express local time.The zone specifies the offset from Coordinated Universal Time (UTC,formerly referred to as "Greenwich Mean Time") that the date andtime-of-day represent.  The "+" or "-" indicates whether thetime-of-day is ahead of (i.e., east of) or behind (i.e., west of)Universal Time.  The first two digits indicate the number of hoursdifference from Universal Time, and the last two digits indicate thenumber of minutes difference from Universal Time.  (Hence, +hhmmmeans +(hh * 60 + mm) minutes, and -hhmm means -(hh * 60 + mm)minutes).  The form "+0000" SHOULD be used to indicate a time zone atUniversal Time.  Though "-0000" also indicates Universal Time, it isused to indicate that the time was generated on a system that may bein a local time zone other than Universal Time and thereforeindicates that the date-time contains no information about the localtime zone.A date-time specification MUST be semantically valid.  That is, theday-of-the-week (if included) MUST be the day implied by the date,the numeric day-of-month MUST be between 1 and the number of daysallowed for the specified month (in the specified year), thetime-of-day MUST be in the range 00:00:00 through 23:59:60 (thenumber of seconds allowing for a leap second; see [STD12]), and thezone MUST be within the range -9959 through +9959.

形如:

Sun 30 Dec 2018 19:42:44 +0800

ISO 8601 Extended Format

ECMAScript defines a string interchange format for date-times based upon a simplification of the ISO 8601 Extended Format. The format is as follows: YYYY-MM-DDTHH:mm:ss.sssZ

Where the fields are as follows:

  • YYYY is the decimal digits of the year 0000 to 9999 in the Gregorian calendar.

  • - “-” (hyphen) appears literally twice in the string.

  • MM is the month of the year from 01 (January) to 12 (December).

  • DD is the day of the month from 01 to 31.

  • T “T” appears literally in the string, to indicate the beginning of the time element.

  • HH is the number of complete hours that have passed since midnight as two decimal digits from 00 to 24.

  • : “:” (colon) appears literally twice in the string.

  • mm is the number of complete minutes since the start of the hour as two decimal digits from 00 to 59.

  • ss is the number of complete seconds since the start of the minute as two decimal digits from 00 to 59.

  • . “.” (dot) appears literally in the string.

  • sss is the number of complete milliseconds since the start of the second as three decimal digits.

  • Z is the time zone offset specified as “Z” (for UTC) or either “+” or “-” followed by a time expression HH:mm

This format includes date-only forms:

  • YYYY
  • YYYY-MM
  • YYYY-MM-DD

It also includes “date-time” forms that consist of one of the above date-only forms immediately followed by
one of the following time forms with an optional time zone offset appended:

  • THH:mm
  • THH:mm:ss
  • THH:mm:ss.sss

All numbers must be base 10. If the MM or DD fields are absent “01” is used as the value. If the HH, mm, or ss fields are absent “00” is used as the value and the value of an absent sss field is “000”. The value of an absent time zone offset is “Z”.

Illegal values (out-of-bounds as well as syntax errors) in a format string means that the format string is not a valid instance of this format.

  • NOTE 1 : As every day both starts and ends with midnight, the two notations 00:00 and 24:00 are available to distinguish the two midnights that can be associated with one date. This means that the following two notations refer to exactly the same point in time: 1995-02-04T24:00 and 1995-02-05T00:00

  • NOTE 2 : There exists no international standard that specifies abbreviations for civil time zones like CET, EST, etc. and sometimes the same abbreviation is even used for two very different time zones. For this reason, ISO 8601 and this format specifies numeric representations of date and time.

精简一下:

ISO 8601 Extended Format : YYYY-MM-DDTHH:mm:ss.sssZ

示例:

1995-12-17T03:24:00+00:00 //标准时间
1995-12-17T03:24:00Z //标准时间
1995-12-17T03:24:00+08:00 //东8区时间

【日期、时间】javascript字符串转日期类型相关推荐

  1. 把一个中文日期时间格式字符串转为日期时间

    MS SQL Server2012中把一个中文日期时间格式字符串转为日期时间. 如: DECLARE @d NVARCHAR(20) = N'2012年08月12日14时36分48秒' SELECT  ...

  2. mysql 日期时间格式化字符串_MySQL日期函数与日期转换格式化函数大全

    Mysql作为一款开元的免费关系型数据库,用户基础非常庞大,本文列出了MYSQL常用日期函数与日期转换格式化函数 1.DAYOFWEEK(date) SELECT DAYOFWEEK('2016-01 ...

  3. 第五部份 01 深入JavaScript与.NET Framework中的日期时间 JavaScript中的Date类型

    参考文章 http://www.cnblogs.com/JeffreyZhao/archive/2007/06/06/Inside_Date_and_Time_in_JavaScript_and_Do ...

  4. python按年月日输出字符串_python日期时间转为字符串或者格式化输出的实例

    python日期时间转为字符串或者格式化输出的实例 如下所示: 年月日时分秒 >>> print datetime.datetime.now().strftime("%Y- ...

  5. hive 时间转字符串_hive日期函数

    hive的函数有很多,今天我带大家来总结下hive中常用的日期函数吧!!! 如有不足,还请大家多多指出,希望能和大家一起交流,共同进步! 时间一点一滴在溜走,我们要珍惜每一刻 1.日期时间转日期函数: ...

  6. SQL日期时间转为字符串

    SQL日期时间转为字符串 SELECTCONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM SELECTCONVERT(varchar(100 ...

  7. python3 日期时间和字符串来回转换

    1.字符串转日期时间 from datetime import date, timedelta, datetimestr_date = '2022-05-08 12:35:46'date_date = ...

  8. 爪哇国新游记之三十一----日期时间与字符串间的转化

    1.由日期时间转化成字符串 Date date = new Date(); Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm ...

  9. mysql日期/时间转换为字符串

    将日期时间2016-05-13 16:07:50转化为字符串20160513date_formatSELECT phone, DATE_FORMAT(time, '%Y%m%d%H%i%s') FRO ...

  10. SqlServer 日期时间格式 字符串相互转换 及相关函数

    一.sql server日期时间函数 Sql Server中的日期与时间函数 1. 当前系统日期.时间 select getdate() 2. dateadd 在向指定日期加上一段时间的基础上,返回新 ...

最新文章

  1. 【飞书成长日记】飞书功能发展路径
  2. AI公司为什么集体造“芯”?寻求商业变现新途径
  3. Python语言规范
  4. Linux_CentOS-服务器搭建 六
  5. iOS-UICollectionView
  6. web 网页截取图片
  7. xrkmonitor监控mysql_xrkmonitor字符云监控系统
  8. 我与电脑1-初识电脑
  9. PDF文件转化成mobi格式,亲测kindle或者iReader可用!
  10. Html div 打印自动分页,真正好用的网页打印和分页方法:CSS+DIV或元素ID
  11. 升级鸿蒙系统最新计划,华为鸿蒙系统更新升级方法分享
  12. Unity 5.5.0f3发行说明
  13. 达内Web前端开发视频教程
  14. GaussDB数据库基础函数介绍-上
  15. 520男生送什么礼物特别、2022特别礼物合集
  16. 腾讯云互动直播分享屏幕小结
  17. Failed to start [powershell.exe](idea 启动前端页面,open in terminal时报错)
  18. 易信电脑版 v2.1.0 PC版
  19. Java中使用IE Proxy代理的方法
  20. 新型公共政务云解决方案

热门文章

  1. Meteor工作目录的划分
  2. request.setCharacterEncoding(utf-8);
  3. 【FBA】SharePoint 2013自定义Providers在基于表单的身份验证(Forms-Based-Authentication)中的应用...
  4. github推送错误:已经有此代码,不允许覆盖的解决方法
  5. android配置开发环境ubuntu
  6. 一款嵌入式监听地图测试软件(开发)
  7. SQL Server 2005合并列成字符串 2008-11-07
  8. 北京某公司.NET面试题
  9. php7.0支持调用lua脚本
  10. python算法与数据结构-希尔排序算法