zoukankan      html  css  js  c++  java
  • javascript Date 函数的坑

    Javascrip中对日期的解析、格式化简直是混乱不堪,各种的坑,攻城狮们多小心。
     
    1. 不要用 Date("yyyy-mm-dd") 构造函数解析字符串。
      IE、firefox、safari 都不支持;
      chrome 支持 Mozilla 标准,会调用 parse() 来解析。
    所以这种用法不可用于跨浏览器的生产代码。
     
    2. Date.parse() 支持的格式:各浏览器实现不一样的,唯一能通用的格式是 ISO8601 标准,
    即:yyyy-mm-ddThh:mm:ss 格式
     
    但 chrome 下带'T'的日期串会被认为是UTC时区,在浏览器上执行时,会用浏览器时区做转换,导致错误。
     
    3. Date 的 month 是从0开始的!2月的值是 1!
     
    最保险的方法是用 new Date(year,month-1,seconds); 方式构造指定时间对象。
         Note that year should have 4-digits, and month starts with 0.
         The date can be created given it’s components in the current time zone.
         For this format there should be at least two first arguments, next ones are optional.
         To create a date given it’s components in UTC time zone, use static method Date.UTC()
     
     
    参考
         moment.js
     
     
  • 相关阅读:
    工厂方法模式
    代理模式
    观察者模式
    策略模式
    单例模式
    简单工厂模式
    lintcode:等价二叉树
    lintcode:被围绕的区域
    lintcode:二叉树的所有路径
    lintcode:快乐数
  • 原文地址:https://www.cnblogs.com/wei-feng/p/3669202.html
Copyright © 2011-2022 走看看