This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 6 years ago.
I need to get the current date and time javascript in the following format
YYYY-MM-DD HH:MM:SS
But cannot work out how to do it.
var d = new Date();
timesheetGrid.cellById(rId,15).setValue(d);
This is where I am using the data.
Any help would be greatly appreciated.
How about simply:
d.toISOString().replace('T', ' ').replace(/\..*$/, '');
Take the ISO string, replace the "T" with a space, and trim off the milliseconds.
Related
This question already has answers here:
Parsing ISO 8601 date in Javascript
(5 answers)
Closed last year.
Time format i have is 2022-02-16T12:33:44Z
How can is make this
2022-02-16
12:33
including br tag.
what i tried was date.split("T") but don't know what to do next
const str = "2022-02-16T12:33:44Z"
str.split("T")[0]
str.split("T")[1].slice(0,-4)
Output
2022-02-16
12:33
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Parsing a string to a date in JavaScript
(35 answers)
Closed 1 year ago.
I have a dateformat
date="11032020"(mmddyyyy)
output expected:11/03/2020
I want to convert this to mm/dd/yyyy in nodejs.I am a begineer to nodejs.
I saw many posts where they convert from mm-dd-yyyy to different format or related.I tried converting to ISO but that did not work out.
I am not able to convert mmddyyyy to different format.
Could you please help me out in this.
If you're certain that the input is MMDDYYYY and don't need to validate it, you could use a regular expression:
let format_date = input => input.replace(/(\d{2})(\d{2})(\d{4})/, "$1/$2/$3")
format_date("11032020") // "11/03/2020"
With moment.js you can do:
const date = "11032020"
const res = moment(date, "MMDDYYYY").format('MM/DD/YYYY')
console.log(res)
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js" integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
This question already has answers here:
Parsing a string to a date in JavaScript
(35 answers)
Closed 4 years ago.
I have string value '05-Jan-18' to be converted to date format using javascript. can someone help me on this.
You can just do:
var d = new Date("05-Jan-18")
Yeah '05-Jan-18' does not work everywhere. However
new Date("05-Jan-18".replace(new RegExp('-', 'g'), ' '))
should work
This question already has answers here:
Why does Date.parse give incorrect results?
(11 answers)
Closed 8 years ago.
There is the following string - "2013-10-23 11:56:29" and timezone name "Europe/Moscow". I hoped to parse it into Date using Date.parse() or new Date(string), but it doesn't work. How can I do it? Thanks.
see the ISO formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS
developer.mozilla.org - JavaScript Date
Converting string to date in js
Use moment.js (http://momentjs.com/docs/#/parsing/string/) and moment timezone (http://momentjs.com/timezone/docs/) for the timezone.
This question already has answers here:
Convert dd-mm-yyyy string to date
(15 answers)
how to parse a "dd/mm/yyyy" or "dd-mm-yyyy" or "dd-mmm-yyyy" formatted date string using JavaScript or jQuery [duplicate]
(5 answers)
Closed 8 years ago.
I have string as 06/08/2013 that I want to convert into Date Object
I do
var transactionDate = Date.parse(transactionDateAsString);
and I get NaN
How can I tell javascript to format the string as dd/mm/yyyy?
Break it down and spoon-feed it:
var parts = transactionDateAsString.split("/");
var date = new Date(parts[2],parts[1]-1,parts[0]);
Date.parse() from the docs:
Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
You probably want to use the Date constructor:
var transactionDate = new Date(transactionDateAsString);