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/ ...
随机推荐
- PHP注册审核做法
1.注册页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. ...
- bzoj3504: [Cqoi2014]危桥
题意:给出一个图,有的边可以无限走,有的只能走两次(从一头到另一头为一次),给定两个起点以及对应的终点以及对应要走几个来回,求判断是否能完成. 先来一个NAIVE的建图:直接限制边建为容量1,无限制为 ...
- 用volley在Genymotion上获取网页源码
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdUAAALUCAIAAADSbz+YAAAgAElEQVR4nOydeVwT197/R+9zu9zluU
- 【JavaScript】固定布局轮播图特效
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Apriori on MapReduce
Apiroi算法在Hadoop MapReduce上的实现 输入格式: 一行为一个Bucket 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 34 36 38 ...
- 封装获取dom元素
<script> //函数: 反复执行的代码块 //全局只有一个对象,防止全局变量污染 var itcast = { getElen : { tag : function(tag){ re ...
- 关于java 定时器的使用总结
直接上代码,代码中有注释(代码中还有一些本人的其他测试,读者可以忽略不计).读者在代码中发现了bug,欢迎指正. package j2se.system.test; import java.text. ...
- c++中变量声明和变量定义的区别。2016年12月6日
整个流程: 1.程序告诉cpu,程序将要使用一个变量.(暂时不一定用到,先说一下.) 2.程序告诉CPU,程序现在就要使用一个变量.(现在就用) 3.cpu按照这个变量的类型,把内存划分出几个单位(b ...
- 【转】Memcached安装
解析:Memcached是什么? Memcached是由Danga Interactive开发的,高性能的,分布式的内存对象缓存系统,用于在动态应用中减少数据库负载,提升访问速度. 一.软件版本 ...
- 一个自定义控件的Demo
里面包括Button.Checkbock.listview.popupwindow的自定义 import android.app.Activity; import android.content.In ...