JavaScript date time formatting

Program ape Owen 2021-01-05 21:07:25
javascript date time formatting


Last note c# The date and time are formatted and printed C# Format date time , Here's the record JS edition . In fact, it's like building wheels over and over again , There are many ready-made class libraries , for example :momentjs. But sometimes it doesn't refer to this class library , It's not that complex a requirement , So it's necessary to write a small method . Let's look at the output record first :

 

Format

result
(2021-01-03 06:07:08.009)

result
(2021-11-22 15:36:48.678)

C#

JavaScript

C#

JavaScript

Year related

y

2021 year 1 month

2021

2021 year 11 month

2021

yy

21

21

21

21

yyy

2021

2021

2021

2021

yyyy

2021

2021

2021

2021

yyyyy

02021

02021

02021

02021

yyyyyy

002021

002021

002021

002021

y-MM-dd

21-01-03

2021-01-03

21-11-22

2021-11-22

yy-MM-dd

21-01-03

21-01-03

21-11-22

21-11-22

yyy-MM-dd

2021-01-03

2021-01-03

2021-11-22

2021-11-22

yyyy-MM-dd

2021-01-03

2021-01-03

2021-11-22

2021-11-22

yyyyy-MM-dd

02021-01-03

02021-01-03

02021-11-22

02021-11-22

yyyyyy-MM-dd

002021-01-03

002021-01-03

002021-11-22

002021-11-22

Month related

M

1 month 3 Japan

1

11 month 22 Japan

11

MM

01

01

11

11

MMM

1 month

1 month

11 month

11 month

MMMM

January

January

November

November

MMMMM

January

January

November

November

yyyy-M-dd

2021-1-03

2021-1-03

2021-11-22

2021-11-22

yyyy-MM-dd

2021-01-03

2021-01-03

2021-11-22

2021-11-22

yyyy-MMM-dd

2021-1 month -03

2021-1 month -03

2021-11 month -22

2021-11 month -22

yyyy-MMMM-dd

2021- January -03

2021- January -03

2021- November -22

2021- November -22

yyyy-MMMMM-dd

2021- January -03

2021- January -03

2021- November -22

2021- November -22

The days are related

d

2021/1/3

3

2021/11/22

22

dd

03

03

22

22

ddd

Sunday

Sunday

Monday

Monday

dddd

Sunday

Sunday

Monday

Monday

ddddd

Sunday

Sunday

Monday

Monday

yyyy-MM-d

2021-01-3

2021-01-3

2021-11-22

2021-11-22

yyyy-MM-dd

2021-01-03

2021-01-03

2021-11-22

2021-11-22

yyyy-MM-ddd

2021-01- Sunday

2021-01- Sunday

2021-11- Monday

2021-11- Monday

yyyy-MM-dddd

2021-01- Sunday

2021-01- Sunday

2021-11- Monday

2021-11- Monday

yyyy-MM-ddddd

2021-01- Sunday

2021-01- Sunday

2021-11- Monday

2021-11- Monday

Hour related 1

h

I won't support it

6

I won't support it

3

hh

06

06

03

03

hhh

06

06

03

03

hhhh

06

06

03

03

h:mm:ss.fff

6:07:08.009

6:07:08.009

3:36:48.678

3:36:48.678

hh:mm:ss.fff

06:07:08.009

06:07:08.009

03:36:48.678

03:36:48.678

hhh:mm:ss.fff

06:07:08.009

06:07:08.009

03:36:48.678

03:36:48.678

hhhh:mm:ss.fff

06:07:08.009

06:07:08.009

03:36:48.678

03:36:48.678

Hour related 1

H

I won't support it

6

I won't support it

15

HH

06

06

15

15

HHH

06

06

15

15

HHHH

06

06

15

15

H:mm:ss.fff

6:07:08.009

6:07:08.009

15:36:48.678

15:36:48.678

HH:mm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

HHH:mm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

HHHH:mm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

It's about minutes

m

1 month 3 Japan

7

11 month 22 Japan

36

mm

07

07

36

36

mmm

07

07

36

36

mmmm

07

07

36

36

HH:m:ss.fff

06:7:08.009

06:7:08.009

15:36:48.678

15:36:48.678

HH:mm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

HH:mmm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

HH:mmmm:ss.fff

06:07:08.009

06:07:08.009

15:36:48.678

15:36:48.678

Second correlation

s

2021-01-03T06:07:08

8

2021-11-22T15:36:48

48

ss

08

08

48

48

sss

08

08

48

48

.........
版权声明
本文为[Program ape Owen]所创,转载请带上原文链接,感谢
https://qdmana.com/2021/01/20210105210621528c.html

  1. css单位
  2. CSS unit
  3. 前端验证集合
  4. Front end validation collection
  5. Front end learning (4) -- response line, response head, response body
  6. Lesson 27: using time measuring tools to explore available spare time
  7. CSS 单位
  8. CSS unit
  9. 前端工具集合
  10. Front end Tools Collection
  11. Introduction to HTTP message format
  12. Introduction to new features of HTML5
  13. Common instructions for Vue
  14. Introduction of bootstrap Blazer component library
  15. HTML5 速览
  16. HTML5 quick view
  17. HTML表格自动排序
  18. For less than $1700, create a private cloud with openstack
  19. Basic learning of JavaScript (1)
  20. 前端编程之路一一HTML标签分类
  21. Front end Programming: HTML tag classification
  22. ColSpan and rowspan merging cells of HTML form elements
  23. JavaScript 日期时间格式化
  24. Classification of front end interview questions - html2
  25. CSS block elements
  26. HTML5 form detailed tutorial
  27. HTML5 form detailed tutorial
  28. HTML5新增的元素表
  29. New element table in HTML5
  30. 3D轮播插件vue-carousel-3d非官方最全文档
  31. 3D carousel plug-in vue-carousel-3d
  32. Uniapp (Vue general) integrates Tencent location service SDK -- multi platform small program general
  33. Slowhttptest slow attack tool use details
  34. HTML summary (2)
  35. Overview of CSS3
  36. Front end abnormal monitoring system
  37. 免费网站部署和免费数据库Serverless云存储资源汇总整理
  38. Free website deployment and collection of free database serverless cloud storage resources
  39. Vux form -- a form solution of base vux
  40. 可以直接用于HTML中的特殊字符表 unicode字符集
  41. Can be directly used in HTML special character table Unicode character set
  42. Detailed explanation of HTTP protocol
  43. HTTP request header and request response header
  44. CSS background深度解析
  45. Python web/HTML GUI
  46. Front end standard 2: HTML you know and don't know
  47. Some HTML tags
  48. HTML标签之table
  49. Table of HTML tag
  50. DataTables of jQuery plug-in
  51. Unity calls Google's free translation API (HTTPS interface). Young people don't speak martial arts. How can they speak in multiple languages
  52. Linux entry most commonly used commands, do not learn a bunch of useless commands
  53. Piziheng embedded: a list of common short-range wireless communication protocols (Wi Fi / Bluetooth / ZigBee / thread...)
  54. Naming rules for the front end team of ladder
  55. HTML logo related symbols
  56. Node . JS: development resources and technology stack arrangement
  57. Unity calls Google's free translation API (HTTPS interface). Young people don't speak martial arts. How can they speak in multiple languages
  58. Straighten out JavaScript (18) - statements and operators
  59. Employment information statistics network (interface document)
  60. css selector