简体   繁体   中英

convert ISO 8601 to specific format using date.js

i have a ISO 8601 time in javascript not i want to convert it into MMM-D mm:ss using date.js but really no idea how can i accomplish it.

here is the sample date 2014-02-26T05:39:27.885Z i am getting this from server and if you convert it , it will appear like Wed, 26 Feb 2014 11:09:27 +05:30 and i want to show it as Feb - 26 09:27

using following i can i achieve this Feb - 26 09:27

    var dateTime = Date.today().toString("MMM-d") +" "+ new Date().toString("mm:ss");

but this is for today's date i want it to fetch it from ISO 8601

Assuming date.js is loaded and you have the time as an ISO-8601 string, first create a Date object with new Date(str) then call .toString("MMM - d mm:ss") on it.

You can see this working in the below snippet.

 var dateStr = "2014-02-26T05:39:27.885Z"; var dateObj = new Date(dateStr); var formattedDate = dateObj.toString("MMM - d mm:ss"); console.log(formattedDate) // => "Feb - 25 39:27" 
 .as-console-wrapper{min-height:100%;} 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/datejs/1.0/date.min.js"></script> 

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