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/ ...
随机推荐
- MSP430FR5739串口程序
今天急着用这个片子的串口,匆忙中调试串口也话费了一段时间,在网上下了一个程序,忽然就把所有问题搞清楚了,只是中断就看着头文件中寄存器写的,虽然通讯正常,不过不确定有没有写错.代码如下: #includ ...
- thunkify和co的邂逅
上一篇说到thunkify的作用,这一篇说一下thunkify和co的集合 co中有一块代码 /** * Convert a thunk to a promise. * * @param {Funct ...
- 计算机网络(8)-----TCP报文段的首部格式
TCP报文段的首部格式 概述 TCP报文段首部的前20个字节是固定的,因此TCP首部的最小长度是20字节. 源端口和目标端口 各占2个字节,分别写入源端口号和目的端口号. 序列号 占4个字节,表示本报 ...
- Swift介绍
Swift介绍 Swift介绍 Swift发布于2014年wwdc大会,是苹果推出的一门编程语言,刚推出的时候主要在os X和iOS平台,今年wwdc大会上,苹果公司宣布今年年底Swift将会开源,开 ...
- angular js 图片轮播
搬运工: eg1: Build a Sweet AngularJS Photo Slider Pt 2 with ngTouch DEMO:http://paul-xiao.github.io/ang ...
- HalconMFC(一)之多版本配置
今天比较匆忙,还得写周六日考试扯P的PPT,就先这样开个头吧.我的电脑是win7,32位的系统,我用Halcon10.0.但是很多小伙伴的都是64位系统的,所以我用小伙伴的64位系统试过很多次用VC配 ...
- linux内核学习之二 一个精简内核的分析(基于时间片轮转)
一 实验过程及效果 1.准备好相关的代码,分别是mymain.c,mypcb.h,myinterrupt.c ,如下图,make make成功: 在qemu创建的虚拟环境下的运行效果:(使用的命令 ...
- AsyncTask异步交互和httpurlconnection结合使用
//网络请求数据 package com.baidu.myutils; import java.io.BufferedReader; import java.io.InputStreamReader; ...
- jQuery初级篇(一)
知识说明: jQuery库是一个javascript库文件,它比起javascript来,写的更少,但做得更多,下面便对刚开始学习jQuery,一些基础知识整理出来,供后期翻阅. 一. jQ ...
- 查询SQLSERVER执行过的SQL记录
SELECT TOP 1000 --创建时间 QS.creation_time, --查询语句 SUBSTRING(ST.text,(QS.statement_start_offset/2)+1, ( ...