This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 6 years ago.
There is simpleDateFormat available in java,similarly is there any way to format the date in JavaScript
What is the best equivalent way to perform date formats in JavaScript.
I think In javascript we don't have straight forward functions to get dateformats, to get the exact format you need to call differnt functions on Date object(in javascript).
but in jqueryUI we have formatDate().
var d = new Date(2016, 0, 30) // 30 Jan 2016
alert( formatDate(d) ) // '30.01.16'
Related
This question already has answers here:
how do I subtract one week from this date in jquery?
(4 answers)
How do I output an ISO 8601 formatted string in JavaScript?
(16 answers)
Closed 6 months ago.
How can I get a UTC timestamp of a week ago in ISO 8601 format (i.e., YYYY-MM-DDTHH:MM:SSZ) using JavaScript?
I don't want to use any libraries.
Using standard Date functions:
const d = new Date();
d.setDate(d.getDate() - 7);
console.log(d.toISOString());
This question already has answers here:
Creating java date object from year,month,day
(6 answers)
java.util.Date and getYear()
(12 answers)
Closed 2 years ago.
Currently I am trying to convert a date calculation from javascript to java, since I want to use it for Android development. So in javascript I was using the method date.valueOf(), which converts the date to the milliseconds that passed since January 1, 1970. In java the method with the same funcionality is called date.getTime(). In the java and javascript documentation the description is exactly the same, but when I am inserting the same date, I am getting two completely different values.
For example:
Java getTime()
Date date = new Date(2011, 10, 1);
System.out.println(date.getTime()); //prints: 61278249600000
Javascript valueOf()
const date = new Date(2011, 10, 1);
console.log(date.valueOf()); //prints: 1320102000000
So my questions are:
Why is this happening? (or what did I wrong?)
How can I correct the code?
It would be awesome if somebody can help me.
The discrepancy isn't between Java's getTime and JavaScript's valueOf, it's the Java Date constructor. The year parameter is years since 1900. So the equivalent Java code would be:
Date date = new Date(110, 10, 1);
// ^−−− 2010 - 1900
This is one of the many reasons not to use the java.util.Date class.
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:
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:
Closed 11 years ago.
Possible Duplicate:
Convert a Unix timestamp to time in Javascript
I am getting date in the form of unixtimestamp
ex: 1321367459.0 (Equivalent to Tue, 15 Nov 2011 14:30:59)
I want to convert the time stamp to date format using javascript
using jquery also no problem
var myDate = new Date(1321367459.0 * 1000);
You can get a Date object using : var d = new Date(milliseconds);.