[关闭]
@JunQiu 2018-12-10T08:02:23.000000Z 字数 5096 阅读 1253

npmInstall、Js_Date()/formart、时间格式、时区

summary_2018/07 language_js npm


1、日常工作


2、技术学习

  1. ### 了解几种时间表示
  2. # GMT即「格林威治标准时间」(GreenwichMeanTime,简称G.M.T.)(以地球自转来计算的,每15度/h,15*24=360)
  3. # UTC是最主要的世界时间标准,是经过平均太阳时(以格林威治时间GMT为准)、地轴运动修正后的新时标以及以「秒」为单位的国际原子时所综合精算而成的时间。UTC比GMT来得更加精准。其误差值必须保持在0.9秒以内,若大于0.9秒则由位于巴黎的国际地球自转事务中央局发布闰秒,使UTC与地球自转周期一致。协调世界时区会使用“Z”来表示。而在航空上,所有使用的时间划一规定是协调世界时。而且Z在无线电中应读作“Zulu”(可参见北约音标字母),协调世界时也会被称为“Zulu time”。(UTC)
  4. # TimeZone&UTC Offsets:时区与偏移
  5. UTC偏移量代表了某个具体的时间值与UTC时间之间的差异,通常用HH:mm形式表述。而TimeZone则表示某个地理区域,某个TimeZone中往往会包含多个偏移量,而多个时区可能在一年的某些时间有相同的偏移量。譬如America/Chicago, America/Denver,以及America/Belize在一年中不同的时间都会包含 -06:00 这个偏移。
  6. # 时间戳
  7. Unix时间戳表示当前时间到19701100:00:00 UTC对应的秒数。注意,JavaScript内的时间戳指的是当前时间到19701100:00:00UTC对应的毫秒数,和unix时间戳不是一个概念,后者表示秒数,差了1000倍。
  8. ## 时间表示格式
  9. 1RFC2822
  10. YYYY/MM/DD HH:MM:SS ± timezone(时区用4位数字表示)
  11. // eg 1992/02/12 12:23:22+0800(后面的+xxx表示与零时区的偏移)
  12. 2ISO 8601:国际标准化组织的国际标准ISO8601是日期和时间的表示方法
  13. YYYY-MM-DDThh:mm:ss ± timezone(时区用HH:MM表示)
  14. 1997-07-16T08:20:30Z
  15. // “Z”表示UTC标准时区,即"00:00",所以这里表示零时区的`1997年7月16日08时20分30秒`
  16. // 转换成位于东八区的北京时间则为`1997年7月17日16时20分30秒`
  17. // 表示东一区的1997年7月16日19时20秒30分:1997-07-16T19:20:30+01:00
  18. // 转换成UTC标准时间的话是1997-07-16T18:20:30Z
  19. ## javaScript Date():Date对象
  20. 1.1、普通函数使用
  21. Date(2000, 1, 1) //无论有没有参数,直接调用Date总是返回当前时间
  22. 1.2、构造函数使用:
  23. new Date();
  24. new Date(value);
  25. new Date(dateString);
  26. new Date(year, month[, day[, hour[, minutes[, seconds[, milliseconds]]]]]);
  27. Tipsnew Date(2013, 0, 1, 0, 0, 0, 0)参数如果超出了正常范围,会被自动折算。比如,如果月设为15,就折算为下一年的4月。
  28. Tips:Date.now返回的是UTC标准时间0时区
  29. 2、创建一个指定日期和时间的方法是解析一个符合ISO 8601格式的字符串
  30. var d = Date.parse('2015-06-24T19:49:22.875+08:00'); // 1435146562875
  31. new Date(1435146562875) //2015-06-24T11:49:22.875Z
  32. 3、日期的运算
  33. 两个日期实例对象进行减法运算时,返回的是它们间隔的毫秒数;进行加法运算时,返回的是两个字符串连接而成的新字符串。
  34. 4、其它一些操作函数
  35. 4.1、实例方法:get获取系统时间:不准确
  36. getTime():返回实例距离19701100:00:00的毫秒数,等同于valueOf方法。
  37. getDate():返回实例对象对应每个月的几号(从1开始)。
  38. getDay():返回星期几,星期日为0,星期一为1,以此类推。
  39. getYear():返回距离1900的年数。
  40. getFullYear():返回四位的年份。
  41. getMonth():返回月份(0表示1月,11表示12月)。
  42. getHours():返回小时(0-23)。
  43. getMilliseconds():返回毫秒(0-999)。
  44. getMinutes():返回分钟(0-59)。
  45. getSeconds():返回秒(0-59)。
  46. getTimezoneOffset():返回当前时间与UTC的时区差异,以分钟表示,返回结果考虑到了夏令时因素。
  47. 4.2 实例方法:set
  48. 4.3、时间格式化
  49. var d = new Date(2013, 0, 1);
  50. d.toString()
  51. // "Tue Jan 01 2013 00:00:00 GMT+0800 (CST)"
  52. d.toUTCString()
  53. // "Mon, 31 Dec 2012 16:00:00 GMT"
  54. d.toISOString()
  55. // "2012-12-31T16:00:00.000Z"
  56. d.toJSON()
  57. // "2012-12-31T16:00:00.000Z"
  58. d.toDateString() // "Tue Jan 01 2013"
  59. d.toTimeString() // "00:00:00 GMT+0800 (CST)"
  60. d.toLocaleDateString()
  61. // 中文版浏览器为"2013年1月1日"
  62. // 英文版浏览器为"1/1/2013"
  63. d.toLocaleTimeString()
  64. // 中文版浏览器为"上午12:00:00"
  65. // 英文版浏览器为"12:00:00 AM"
  66. 5javaScript Date()的一些问题
  67. 1、当从数据库取出时间数据类型的数据类型时,数据的格式可能会发生改变(应该在js中存储为时间戳后,再取出来。。)
  68. mysql的解决方案:不以Date类型返回
  69. 1connect连接时:dateStrings:强制timestamp,datetime,data类型以字符串类型返回,默认false
  70. 2date_format(article_date+’’, ‘%Y-%m-%d %H:%m:%S’) as date;
  71. pqsql:可以使用to_char来解决,可能会产生时区问题,比如取出来之后放回去就没有时区了
  72. 2、在数据库中最好以时间戳表示,避免时区的转换问题/或者带上时间所在的时区
  73. 3、存储时间的格式,可能时带时区的,也可能是不带时区的,带时区时转换是没问题,但是!!!Tips:当没有时区时,是以当前服务器所在的时区为基准进行转换,可能不是原时间所在的时区。
  1. ## Description
  2. This command installs a package, and any packages that it depends on. If the package has a package-lock or shrinkwrap file, the installation of dependencies will be driven by that, with an npm-shrinkwrap.json taking precedence if both files exist. See package-lock.json and npm-shrinkwrap.
  3. A package is:
  4. a) a folder containing a program described by a package.json file
  5. b) a gzipped tarball containing (a)
  6. c) a url that resolves to (b)
  7. d) a <name>@<version> that is published on the registry (see npm-registry) with (c)
  8. e) a <name>@<tag> (see npm-dist-tag) that points to (d)
  9. f) a <name> that has a "latest" tag satisfying (e)
  10. g) a <git remote url> that resolves to (a)
  11. Tips:我只介绍几个常见用法,其它有需要可以查看原文
  12. 1npm install
  13. Install the dependencies in the local node_modules folder.
  14. -g or --global:
  15. In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.(安装为全局)
  16. // 会安装哪些内容 devDependencies or Dependencies
  17. By default, npm install will install all modules listed as dependencies in package.json.
  18. With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
  19. // only install devDependencies or non-devDependencies
  20. The --only={prod[uction]|dev[elopment]} argument will cause either only devDependencies or only non-devDependencies to be installed regardless of the NODE_ENV.
  21. 2npm install sax
  22. npm install saves any specified packages into dependencies by default. Additionally, you can control where and how they get saved with some additional flags:(默认保存至dependencies,可以指定额外选项来指定位置)
  23. -P, --save-prod: Package will appear in your dependencies. This is the default unless -D or -O are present.
  24. //保存至devDependencies中
  25. -D, --save-dev: Package will appear in your devDependencies.
  26. -O, --save-optional: Package will appear in your optionalDependencies.
  27. --no-save: Prevents saving to dependencies.
  28. When using any of the above options to save dependencies to your package.json, there are two additional, optional flags:
  29. -E, --save-exact: Saved dependencies will be configured with an exact version rather than using npm\'s default semver range operator.
  30. -B, --save-bundle: Saved dependencies will also be added to your bundleDependencies list.
  31. Further, if you have an npm-shrinkwrap.json or package-lock.json then it will be updated as well.
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注