This question already has answers here:
javascript: how to parse a date string
(4 answers)
Closed 5 years ago.
I want to convert 06/29/2017 10:13AM to a Javascript Date instance. Currently I split the time into 06/29/2017 and 10:13AM and converted 06/29/2017 using Date('06/29/2017').getTime(). I want to convert the time using the same way and adding the two together, but it isn't working. How should I go about doing this and is there a better way to do it?
Assuming you simply want to convert it a Date-object, try using an UTC date:
new Date('2017-06-29T10:13:00+00:00'); // change to desired time zone
Related
This question already has answers here:
How to change date format in JavaScript [duplicate]
(5 answers)
Closed 11 months ago.
In JavaScript I have a variable that contains a series of dates all formatted like this:
5/3/2021 12:00:00 AM
How can I update that variable to change the format of the date to this:
May 3
dates.map(d => d.toDateString().split(' ').slice(1, 3).join(' '))
This question already has answers here:
Convert varchar to time
(2 answers)
Closed 2 years ago.
I have a ''varchar'' like '2020-08' in ''sql'' table. I need to convert it like 'Aug 2020' to show it in my web page.
select convert(varchar,'2020-08',107)
This does not seem to work.
Ciao, why don't convert data directly in web page using moment? Something like:
let data = '2020-08';
console.log(moment('2020-08').format("MMM YYYY"))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>
This question already has answers here:
How do I format a date in JavaScript?
(68 answers)
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 5 years ago.
Does Javascript not have any built in support for formatting dates? I have a date object, and I want to format it to a format of my choice e.g. the date that I want to convert is '2017-12-22'. Is there not any function that I could use
something like var newFormattedDate = new Date('2017-12-22', 'mm/dd/yyyy')
so that the output is 22/12/2017
Javascript doesn't have support to give format to date. You can use moment.js.
Alternatively, you can use string#replace.
console.log('2017-12-22'.replace(/(....)-(..)-(..)/g,'$3/$2/$1'));
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
This question already has answers here:
extract time from datetime using javascript
(10 answers)
Closed 8 years ago.
Is it possible to get the time from the following datetime in javascript?
2014-11-24 08:30:00
Any help would be appreciated.
UPDATE
Found the solution to my problem in the duplicate:
datetime.substr(11, 5);
//returns 08:30
Thanks for all your help!
What about slice? It should be the fastest when you know you always get datetime (and time is in last 8 chars).
var datetime = "2014-11-24 08:30:00";
var time = datetime.slice(-8);
alert(time); // returns "08:30:00"
new Date("2014-11-24 08:30:00").getTime();
This code block will get time from your exact date.