Format Date as "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
Call the toISOString()
method:
var dt = new Date("30 July 2010 15:05 UTC");
document.write(dt.toISOString());
// Output:
// 2010-07-30T15:05:00.000Z
Convert Javascript Date to YYYY-MM-DDTHH:MM:SS+00:00 (with timezone offset)
There is a NPM package which may do what you want to do in terms of converting these date-times. the link is attached below to the packages NPM page.
https://www.npmjs.com/package/date-and-time
I believe you can use the date.compile() function for your specified results.
How to convert dateTime to yyyy-MM-ddTHH:mm:ss.fffZ in Javascript?
You can use toISOString()
to get ISO date format:
var timeNow = new Date().toISOString();
Convert yyyy-MM-ddTHH:mm:ss.fffZ date format in mmm dd hh:mm using JavaScript
While usually people do use Moment.js for complex date manipulation, this problem can be solved quite trivially with vanilla JS string manipulation and the Date#toUTCString
method.
function formatDate(date) { var utc = date.toUTCString() // 'ddd, DD MMM YYYY HH:mm:ss GMT' return utc.slice(8, 12) + utc.slice(5, 8) + utc.slice(17, 22)}
console.log( formatDate(new Date('2017-02-08T09:19:47.550Z'))) //=> 'Feb 08 09:19'
How to convert yyyy-mm-dd't'hh:mm:ssZ to normal time javascript?
Easy enough using momentjs, it already understands the ISO8601 formats for time and date strings.
let str = '2018-07-30T15:01:13Z';let date = moment(str);
console.log(date.format('llll'));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.min.js"></script>
How to convert time format YYYY-MM-DDTHH:mm:ss.sssZ to MM-DD-YY and standard time
You may want to use new Date(dateString)
and dateObj.toLocaleTimeString([locales[, options]])
:
var date = new Date('2017-02-17T22:32:25.000Z');var formatOptions = { day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', hour12: true };var dateString = date.toLocaleDateString('en-US', formatOptions);// => "02/17/2017, 11:32 PM"
dateString = dateString.replace(',', '') .replace('PM', 'p.m.') .replace('AM', 'a.m.');// => "02/17/2017 11:32 p.m."
console.log(dateString);
Convert date string from ISO 8601 format (YYYY-MM-DDTHH:mm:ss.sssZ ) to 'DD-MM-YYYY HH:mm`
Since your input string has all the necessary parts, you may break it into pieces (e.g. using String.prototype.split()
) and build up anew in desired order and with necessary delimiters:
const dateStr = '2020-06-21T10:15:00Z', [yyyy,mm,dd,hh,mi] = dateStr.split(/[/:\-T]/) console.log(`${dd}-${mm}-${yyyy} ${hh}:${mi}`)
.as-console-wrapper{min-height:100%;}
Related Topics
Angular Conditional Readonly/Disable on Input Fields
Vue.Js - How to Call Method from Another Component
Is There a Function in Lodash to Replace Matched Item
Display HTML Form Values in Same Page After Submit Using Ajax
Open the File Upload Dialogue Box Onclick the Image
How to Convert Formdata (Html5 Object) to Json
How to Remove the Div That a Button Is Contained in When the Button Is Clicked
React Router Not Working After the Page Refresh
Filter Array of Dates Between Two Dates
Safari: Focus Event Doesn't Work on Button Element
Typeerror: Router.Use() Requires Middleware Function But Got a Object
Accessing Variables from Other Functions Without Using Global Variables
Redirect Another Page After Successful Form Submission
React Native Init Android,Ios and App Folder Missing
Reload Content in Modal (Twitter Bootstrap)
Efficiently Replace All Accented Characters in a String