safari 日期对象新建new Date( timeStr ) 参数TimeStr格式
这是一个浏览器兼容的问题,在此总结一下,别老在这掉坑。
先坐下测试
var timeStrArray = [
'2016-10-04',
'2016.10.04',
'2016/10/04', '10-04-2016',
'10.04.2016',
'10/04/2016',
];
for (var i = 0,len = timeStrArray.length; i < len; i++) {
var timeStr = timeStrArray[i];
console.log(new Date(timeStr));
}
在Chrome中的结果
Tue Oct 04 2016 00:00:00 GMT+0800 (中国标准时间)
Tue Oct 04 2016 08:00:00 GMT+0800 (中国标准时间)
Tue Oct 04 2016 00:00:00 GMT+0800 (中国标准时间)
Tue Oct 04 2016 00:00:00 GMT+0800 (中国标准时间)
Tue Oct 04 2016 00:00:00 GMT+0800 (中国标准时间)
Tue Oct 04 2016 00:00:00 GMT+0800 (中国标准时间)
在safari中的结果
Invalid Date
Invalid Date
Tue Oct 04 2016 00:00:00 GMT+0800
Invalid Date
Invalid Date
Tue Oct 04 2016 00:00:00 GMT+0800
可以看到只有以‘/’分隔的字符串能真确的生成日期对象。
这是只有 年 月 日 三个日期的字符串还有包含时间的字符串
var timeStrArray = [
// 加上时间
'2016-10-04 20:09:23',
'2016.10.04 20:09:23',
'2016/10/04 20:09:23', '10-04-2016 20:09:23',
'10.04.2016 20:09:23',
'10/04/2016 20:09:23',
];
结果同上
关于Date日期标准,原文截取 ECMA-262 standard 内容进行说明,引文如下
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 in the Gregorian calendar. "-" (hyphon) 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. ":" (colon) appears literally twice in the string. mm is the number of complete minutes since the start of the hour as two decimal digits. ss is the number of complete seconds since the start of the minute as two decimal digits. "." (dot) appears literally in the string. sss is the number of complete milliseconds since the start of the second as three decimal digits. Both the "." and the milliseconds field may be omitted. 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-DDIt also includes time-only forms with an optional time zone offset appended: THH:mm THH:mm:ss THH:mm:ss.sss.Also included are "date-times" which may be any combination of the above.
safari 日期对象新建new Date( timeStr ) 参数TimeStr格式的更多相关文章
- 在EL表达式或者Struts标签库中格式化日期对象,即将Date转换为yyyy-MM-dd格式
一.EL表达式 首先,在jsp页面引入<fmt> tags,<%@ taglib prefix="fmt" uri="http://java.sun.c ...
- 常用封装--Date篇--获取格式化的日期对象
虽然日期对象可以使用new Date()来获取,但是对于其格式却必须进行相应的转换,才能成为开发者想要的格式. 这里提供了一个封装的方法,通过结合正则表达式的使用,达到了可以对时间对象进行处理,生成多 ...
- js 日期对象Date以及传参
创建一个日期对象,日期对象可传参new Date() 创建日期对象getFullYear() 获取年份 getMonth() 获取月份 返回值是 0(一月) 到 11(十二月) 之间的一个整数 get ...
- 日期对象-Date
新建日期对象 var date = new Date(); getTime() 从 1970年 1月 1日开始计算到 Date 对象中的时间之间的毫秒数. getFullYear() ...
- JavaScript中Date(日期对象),Math对象--学习笔记
Date对象 1.什么是Date对象? 日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 语法:var Udate=new Date(); 注:初始值为当前时间(当前电脑系统 ...
- JavaScript Date日期对象以及日期格式化方法
前言 Date对象是javascript语言中内置的数据类型,用于提供日期和时间的操作接口.Date对象是在早期java中的java.util.Date类基础上创建的,为此,Date类型使用自UTC1 ...
- (70)Wangdao.com第十一天_JavaScript 日期对象 Date
日期对象 Date 表示一个时间 Date 对象是 JavaScript 原生的时间库 它以1970年1月1日00:00:00作为时间的零点,可以表示的时间范围是前后各1亿天(单位为毫秒) 时间零点( ...
- js之Date(日期对象)
通过日期对象我们可以进行一些对日期时间的操作处理 一.日期对象的创建: var myDate=new Date() 二.Date对象方法: Link:http://www.w3school.com.c ...
- js动态获取当前系统时间+js字符串转换为date日期对象
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
随机推荐
- C#遍历XML文件动态加载菜单
通过遍历XML文件动态加载菜单,顺便利用WebBrowser控件实现一个简单的桌面浏览器 效果如下: 代码如下: XMLFile1.xml <?xml version="1.0&quo ...
- 重置了下系统好多关于mysql密码的文章都很渣拷分好的备用
方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass ...
- xcode6 使用pch出错解决办法
1down vote If you decide to add a .pch file manually and you want to use Objective-C just like befor ...
- jsp 动态包含和静态包含
jsp其实就是一个servlet或者说一个java文件,做这样三件事:打印html标签到页面,处理逻辑,输出结果 现在有两个jsp文件,包含者1和被包含者2 静态包含,就是把2的java代码塞到1的代 ...
- html input节点很多 json字符串提交解决方法
遇到一个页面,38个input节点,页面前端写好的,不太容易改成 js框架 容易操作的样式,只能自己想办法一个一个id获取然后 setvalue getvalue(miniui): 38个一个一个写太 ...
- 一步一步搭框架(asp.netmvc+easyui+sqlserver)-01
一步一步搭框架(asp.netmvc+easyui+sqlserver)-01 要搭建的框架是企业级开发框架,适用用企业管理信息系统的开发,如:OA.HR等 1.框架名称:sampleFrame. 2 ...
- PHP 单引号 与双引号区别
在PHP中,字符串的定义可以使用单引号,也可以使用双引号. PHP允许我们在双引号串中直接包含字串变量,双引号串中的变量将被解释而且替换,而单引号串中的内容总被认为是普通字符.例如: $foo = 2 ...
- MVC 请求处理流程(一)
路由系统先获取路由数据,在实现了IHttpModule接口的UrlRoutingModule对象中通过注册HttpApplication的PostResolveRequestCache来解析路由数据并 ...
- script标签里的defer属性
入职新公司,看代码的时候注意到有的script标签中有一个defer属性,查了一下.在这里分享出来. 需要注意的有三点,其中前两点是在错误中分辨出来的: 错误来源:http://www.w3schoo ...
- Varnish常用相关命令工具
varnishd启动./varnishd -f /usr/local/varnish-3.0.2/etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1: ...