如何将时间格式更改为另一种格式?

huangapple go评论72阅读模式
英文:

How to change time format to another format?

问题

I have a date string value

let stringData = '2020/01/06 Mon 17:30';

I want to change the date string becomes to 2020-01-06 17:30:00

Here is what I try:

import momentTimezone from 'moment-timezone';

let stringData = '2020/01/06 Mon 17:30';

stringData = momentTimezone(stringData).tz('Asia/Taipei').format('YYYY-MM-DD HH:mm:ss');

but console.log(stringData) shows Invalid date

then I try:

start_time = moment(stringData, "YYYY/MM/DD ddd").format("YYYY-MM-DD HH:mm:ss"); 

get 2020-01-06 00:00:00

Is any way achieve it ?

英文:

I have a date string value

let stringData = '2020/01/06 Mon 17:30';

I want to change the date string becomes to 2020-01-06 17:30:00

Here is what I try:

import momentTimezone from 'moment-timezone';

let stringData = '2020/01/06 Mon 17:30';

stringData = momentTimezone(stringData).tz('Asia/Taipei').format('YYYY/MM/DD HH:mm:ss');

but console.log(stringData) shows Invalid date

then I try:

start_time = moment(stringData, "YYYY/MM/DD ddd").format("YYYY/MM/DD HH:mm:ss"); 

get 2020/01/06 00:00:00

Is any way achieve it ?

答案1

得分: 1

这是一个可运行的示例

你可以只移除Mon,因为日期已经包含了星期一。

英文:

Here's a working example

You can just remove the Mon since the day is already included on the date.

答案2

得分: 0

显示无效日期,因为您在日期字符串中包含了日期。

让字符串数据 = '2020/01/06 17:30';

时刻(字符串数据, "YYYY-MM-YY HH:mm:ss")

英文:

showing Invalid date because you are including day in you date string

let stringData = '2020/01/06 17:30';

moment(stringData ,"YYYY-MM-YY HH:mm:ss")

huangapple
  • 本文由 发表于 2020年1月6日 15:14:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608053.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定