为moment.js正名

2023-05-16

说来也奇怪,总有人在耳边说moment.js对国际化日期支持不好,坚决不要使用,会带来很多问题之类的话。但就我个人经验来看,还从未见到过任何一个反例,恰好我又是个不信邪的人,并坚持认为检验真理的唯一标准就是小马过河,所以今儿我就准备趟趟水,是骡子是马,咱们拉出来溜溜呗,走起来。

 

首先,部署方式有如下几种:

npm install moment --save   # npm
yarn add moment             # Yarn
Install-Package Moment.js   # NuGet
spm install moment --save   # spm
meteor add momentjs:moment  # meteor
bower install moment --save # bower (deprecated)

这里我选择了npm install的方式。随后引入moment-with-locales.min.js,开始编写一段简单的测试代码。

<html>
    <head>
    </head>
    <body>
        <script src="moment-with-locales.min.js" charset="UTF-8"></script>
        <script type="text/javascript">
            //loc is the locale that get from browser
            moment.locale(loc);
            document.write(moment().format('LT'));
            document.write("</br>");
            document.write(moment().format('LTS'));
            document.write("</br>");
            document.write(moment().format('L'));
            document.write("</br>");
            document.write(moment().format('l'));
            document.write("</br>");
            document.write(moment().format('LL'));
            document.write("</br>");
            document.write(moment().format('ll'));
            document.write("</br>");
            document.write(moment().format('LLL'));
            document.write("</br>");
            document.write(moment().format('lll'));
            document.write("</br>");
            document.write(moment().format('LLLL'));
            document.write("</br>");
            document.write(moment().format('llll'));
        </script>
    </body>
</html>

打印结果如下。

//fr
11:50
11:50:01
21/07/2018
21/7/2018
21 juillet 2018
21 juil. 2018
21 juillet 2018 11:50
21 juil. 2018 11:50
samedi 21 juillet 2018 11:50
sam. 21 juil. 2018 11:50

//de
11:50
11:50:38
21.07.2018
21.7.2018
21. Juli 2018
21. Juli 2018
21. Juli 2018 11:50
21. Juli 2018 11:50
Samstag, 21. Juli 2018 11:50
Sa., 21. Juli 2018 11:50

//it
11:51
11:51:55
21/07/2018
21/7/2018
21 luglio 2018
21 lug 2018
21 luglio 2018 11:51
21 lug 2018 11:51
sabato 21 luglio 2018 11:51
sab 21 lug 2018 11:51

//zh-cn
11:52
11:52:35
2018/07/21
2018/7/21
2018年7月21日
2018年7月21日
2018年7月21日中午11点52分
2018年7月21日 11:52
2018年7月21日星期六中午11点52分
2018年7月21日星期六 11:52

//zh-tw
11:53
11:53:52
2018/07/21
2018/7/21
2018年7月21日
2018年7月21日
2018年7月21日 11:53
2018年7月21日 11:53
2018年7月21日星期六 11:53
2018年7月21日星期六 11:53

//ko-kr
오전 11:54
오전 11:54:25
2018.07.21.
2018.07.21.
2018년 7월 21일
2018년 7월 21일
2018년 7월 21일 오전 11:54
2018년 7월 21일 오전 11:54
2018년 7월 21일 토요일 오전 11:54
2018년 7월 21일 토요일 오전 11:54

//ja-jp
11:54
11:54:51
2018/07/21
2018/07/21
2018年7月21日
2018年7月21日
2018年7月21日 11:54
2018年7月21日 11:54
2018年7月21日 土曜日 11:54
2018年7月21日(土) 11:54

//es
11:55
11:55:20
21/07/2018
21/7/2018
21 de julio de 2018
21 de jul. de 2018
21 de julio de 2018 11:55
21 de jul. de 2018 11:55
sábado, 21 de julio de 2018 11:55
sáb., 21 de jul. de 2018 11:55

//ar
١١:٥٥
١١:٥٥:٤٠
٢١/‏٧/‏٢٠١٨
٢١/‏٧/‏٢٠١٨
٢١ يوليو ٢٠١٨
٢١ يوليو ٢٠١٨
٢١ يوليو ٢٠١٨ ١١:٥٥
٢١ يوليو ٢٠١٨ ١١:٥٥
السبت ٢١ يوليو ٢٠١٨ ١١:٥٥
سبت ٢١ يوليو ٢٠١٨ ١١:٥٥

//ru
11:56
11:56:54
21.07.2018
21.7.2018
21 июля 2018 г.
21 июля 2018 г.
21 июля 2018 г., 11:56
21 июля 2018 г., 11:56
суббота, 21 июля 2018 г., 11:56
сб, 21 июля 2018 г., 11:56

//pt-br
11:58
11:58:12
21/07/2018
21/7/2018
21 de julho de 2018
21 de jul de 2018
21 de julho de 2018 às 11:58
21 de jul de 2018 às 11:58
Sábado, 21 de julho de 2018 às 11:58
Sáb, 21 de jul de 2018 às 11:58

//pt
11:58
11:58:52
21/07/2018
21/7/2018
21 de julho de 2018
21 de jul de 2018
21 de julho de 2018 11:58
21 de jul de 2018 11:58
Sábado, 21 de julho de 2018 11:58
Sáb, 21 de jul de 2018 11:58

相信大家也都看到了,so far so good, isn’t it? 另外moment还有很多的使用办法和技巧,例如fromNow、list of locales之类的,同时提供高度可定制化解决方案。至于为啥有人坚决抵制,我只能说,我就静静的坐在这里,等着您提出的任何一个反例吧。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

为moment.js正名 的相关文章

随机推荐

  • 怎么压缩pdf文档大小?在线pdf压缩工具分享

    大多数公司使用 PDF 格式文档来共享信息 存储文件 传递数据等等 xff0c 但是由于PDF文档体积较大 xff0c 上传和下载速度较慢 xff0c 限制了PDF文档的使用 xff0c 那么这时候就需要用到pdf压缩 xff08 http
  • 【教程&工具】微信同步文章到Bear

    在我日常工作中 xff0c 我会将各种互联网以及生活中产出的信息汇总到Bear xff0c 再通过Bear的云同步使我各个终端的信息保持一致 以前在使用有道云笔记的时候 xff0c 有个功能我很喜欢 xff0c 就是当看到一篇想收藏的文章的
  • CentOS7分布式部署pyspider

    1 搭建环境 xff1a 系统版本 xff1a 96 Linux centos linuxpython版本 xff1a span class typ Python span span class lit 3 5 span span clas
  • 各类python包的安装方法及设置安装路径

    python拥有非常丰富的扩展包 xff0c 下面介绍常见的扩展包安装方法 使用Anaconda集成环境 通过使用该python的集成环境 xff0c 可以解决大部分常见包的安装以相互依赖问题 下载地址为 xff1a https www c
  • 如何取出列表内元组中的字典的key和value

    目录标题 一 从列表中取出字典的key和value二 取出列表内元组中的字典的key和value 一 从列表中取出字典的key和value 例 list 1 span class token operator 61 span span cl
  • 树莓派远程桌面连接出现Connection Problem, giving up

    树莓派4B xff0c 使用官方imager刷系统 xff0c 系统为当下最新的2022 01 28 raspios bullseye armhf xff0c 结果发现使用远程桌面登录时 xff0c 在输入用户名和密码后 xff0c 界面无
  • you-get 下载bilibili视频

    bilibili查看视频清晰度 you get i url https www bilibili com video BV17z411i7er p 61 1 debug 下载视频 you get format 61 flv1080 http
  • 解决“AttributeError: ‘str‘ object has no attribute ‘decode‘”问题

    问题描述 在跑代码的时候出现报错提示 Traceback most recent call last File 34 multi detect Nerual py 34 line 4 in lt module gt import BiLST
  • NGINX 进程通信机制

    本文地址 xff1a http blog csdn net spch2008 article details 38945033 nginx的进程通信分为三种类别 xff1a linux 系统与nginx 通信 xff0c master 进程
  • Could not find main class com/intellij/idea/Main

    Could not find main class com intellij idea Main 下载完Pycharm xff0c 打开时显示Could not find main class com intellij idea Main
  • 记事本里打“联通”为什么会变成乱码?

    记事本的编码问题 xff0c 当文档中所有字符都在 C0 AA DF 80 BB BF 这个范围的时候 xff0c notepad都无法确认文档的格式 xff0c 没有自动按照UTF 8格式来 34 Display 34 34 联通 34
  • 思博伦Spirent Testcenter交换机性能测试主要技术指标_丢帧率/吞吐量/转发速率之间的关系_双极未来

    转发速率 丢帧率和吞吐量是描述交换机转发性能的主要技术指标 xff0c 这些指标的测试结果可以客观地反映出被测交换机的性能 正确理解它们之间的联系与区别对于设计吞吐量 丢帧率和转发速率的测试方法非常重要 如下图所示 xff0c X轴表示 x
  • OpenStack-Ceilometer项目功能与架构介绍

    1 OpenStack Ceilometer项目简介 OpenStack通过Telemetry项目提供计量与监控服务 xff0c 该项目旨在针对组成已部署云的物理和虚拟资源 xff0c 可靠地收集并保存各类使用数据 xff0c 以便对这些数
  • redhat 查询端口占用

    linux redhat 端口和服务的查看与终止 redhat 查询端口占用情况和杀死占用的服务 netstat anp grep lt 端口号或者程序名称 gt 查8080端口占用情况 netstat anp grep 8080 查jav
  • mapl

    business card case executive veto power anime stream radio johann strauss black layout pink star job interview question
  • Knowledge Tracing: A Survey阅读笔记

    xff08 注 xff1a 为了方便后续阅读KT论文 xff0c 文中一些名词使用英文 文中保留的序号与原论文参考文献一致 行文会在后续反刍过程中改进 xff09 原文链接 xff1a https arxiv org abs 2201 06
  • iOS_NSAttributedString 的21种属性详细介绍(图文混排)

    说明 NSAttributedString 可以非常方便的实现文字排版和图文混排功能 共有21中效果 API 本文将较详细的介绍21种的属性的使用 注 本博客由 64 凡俊编写 64 Scott 64 春雨 审核 若转载此文章 请注明出处和
  • ++和--的用法

    单独使用时 xff0c 43 43 或者 无论是放在变量的前面还是后面 xff0c 结果是一样的 参与操作时 如果 43 43 或者 在变量的后面 xff0c 先拿变量参与操作 xff0c 后变量做 43 43 或者 例如 int a 61
  • geoserver集群

    软件准备 geoservertomcat 插件 下载地址 xff1a https build geoserver org geoserver activeMQ broker plugin zipjms cluster plugin zip
  • 为moment.js正名

    说来也奇怪 xff0c 总有人在耳边说moment js对国际化日期支持不好 xff0c 坚决不要使用 xff0c 会带来很多问题之类的话 但就我个人经验来看 xff0c 还从未见到过任何一个反例 xff0c 恰好我又是个不信邪的人 xff