This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to format a JSON date?
I have a JSON that contains some dates that I need to be in a UTC format.
At present if I alert the dates out they are in the following format:
/Date(1329314400000)/
I am trying to loop round the JSON but am unsure on how to convert the above date format to UTC.
If anyone has any advice I would greatly appreciate it.
Check this out: How do I format a Microsoft JSON date?
var date = new Date(parseInt(jsonDate.substr(6)));
Related
This question already has answers here:
Parsing a Auto-Generated .NET Date Object with Javascript/JQuery
(2 answers)
How do I format a date in JavaScript?
(68 answers)
Ignore timezone offset while converting date - javascript
(2 answers)
Closed 12 months ago.
I'm Trying to convert the below string to date in the format(dd-mm-yyyy)
let dob = /Date(1646764200000+0530)/
The above value of Date is given in string,
How to convert it to date using JavaScript,
Tried a lot of methods, but it shows an error as invalid date.?
Converting to the DD-MM-YYYY requires formatting.
Here is one way to extract the date portion using the slice() method then formatting the output to your desired format. This assumes that the input date is always in the same form and length.
let dob = /Date(1646764200000+0530)/;
let date = new Date(+(""+dob).slice(6,19)).toLocaleString('en-GB',{year:"numeric",day:"2-digit",month:"2-digit"}).split("/").join("-");
console.log(date)
This question already has answers here:
Format JavaScript date as yyyy-mm-dd
(50 answers)
Closed 2 years ago.
Does anyone know how to format this MySQL response to have JUST the date in the format of MM-DD-YYYY? For example, I want the below response to be formatted in 12-02-2020
date: '2020-12-02T08:00:00.000Z'
I tried doing the lines below but didn't seem to work
let formattedDate = new Date(Date.parse(entry.date.replace(/-/g, '/')));
You can use date_format() in your SQL query:
date_format(mydate, '%m-%d-%Y')
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Closed 2 years ago.
I want to convert the JavaScript date object
let date = Date.now();
to date in RFC 3339 format, so it would return like this:
2020-05-21T08:01:48+00:00
How can I convert it? Get Help! Thank you!~
Try toISOString.
new Date('2020-05-21 08:01:48').toISOString()
This question already has answers here:
Moment.js - How to convert date string into date?
(3 answers)
Closed 3 years ago.
I am getting my date from PHP in format ymd. I am using Moment.js to convert it to format I need, but it's not working properly.
So for example today's date is comes like 190528 but after conversion to YYYY-MM-DD it becomes 190528-1-1 instead of 2019-05-28.
Is it the first format of the date which causes the problem, or there is a way to overcome this and convert it the way I need?
Parse Date first by passing format as 'YYMMDD'
moment("190528", "YYMMDD").format("YYYY-MM-DD");
This will give proper output.
You do not need to load moment for this.
You can break the string into parts of years, month and date. Format the year and return the joined string...
function formatDate(date) {
var _d = date.match(/.{1,2}/g);
_d[0] = "20" + _d[0];
return _d.join("-");
}
var d = "190528";
console.log(formatDate(d));
You need to tell moment what format your date string is in:
console.log(moment("190528", "YYMMDD"))
<script src="https://unpkg.com/moment#2.24.0/moment.js"></script>
You can pass the format of current date as a second param of moment.
console.log(moment("190528", "YYMMDD").format("YYYY-MM-DD"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
Here the docs.
This question already has answers here:
Problem with date formats in JavaScript with different browsers
(4 answers)
Closed 7 years ago.
new Date().toLocaleString() --> "24/09/2015 10:14:00 PM"
new Date("2015-09-24 09:38:32.639").toLocaleString() --> "Invalid Date"
How can I format a date object from a timestamp in string format?
SOLUTION: At the end I got it fixed changing my date type in the server from DateTime to Instant, js will atomatically add zone offset automatically from a timestamp and will format the dates in the right way.
NOTE: I know this question is duplicated, however the solution proposed is different and may help other users to get a different approach to their code.
var myDate = "2015-09-24 09:38:32.639";
new Date(myDate.replace(/-/g,"/")).toLocaleString()
Now it's working fine