英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论