简体   繁体   中英

How to convert date to desired format?

Given date in ISO-8061: "2021-06-11T13:12:42.777" I would like to convert it to format dd/HHmm'Z' which is 11/1312Z (or z, whatever). I have tried:

  • console.log(moment(date).tz('UTC').format('DD/HHmm') + 'z') which prints 11/1112z
  • console.log(moment(date).format("DD/HHmm'Z'")) which prints 11/1312'+02:00' which is good, but I do not want this '+02:00'

This date is UTC timezone.

I have created a fiddle for you, have a look. https://jsfiddle.net/muof5aLq/

var date = "2021-06-11T13:12:42.777";
var now = moment(date).format('DD/HHmm') + 'z';
console.log(now);

Prints

"11/1312z"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM