Day of tomorrow's show date in javascript [duplicate] - javascript

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Add days to DateTime using JavaScript
if today's date of 5-12-2012, I want to display the date the next day 6-12-2012. How is that coded in javascript?

var date = "5-12-2012";
var datum = new Date(date);
datum.setDate(datum.getDate() + 1);
date = datum.getDate() + "-" + (datum.getMonth() + 1) + "-" + datum.getFullYear();

Related

How to convert UTC to IST time format [duplicate]

This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Convert date to another timezone in JavaScript
(34 answers)
Closed 5 years ago.
Input:- 2018-01-19T17:04:54.923Z;
Output:- 2018-01-19 17:04:54;
How can I get universal logic which will work in all browsers in JAVASCRIPT
You can use this:
var dt = new Date('2018-01-19T17:04:54.923Z');
var formatedString = dt.getFullYear() + "-" + dt.getMonth() + 1 + "-" + dt.getDate() + " " + dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
console.log(formatedString);
In javascript you can convert UTC date to local date format using below snippets.
// Your input date
var utcDate = new Date('2018-01-19T17:04:54.923Z');
//Converted UTC to local(IST, etc.,,)
console.log(utcDate.toUTCString());
/*
Output is : "Fri, 19 Jan 2018 17:04:54 GMT"
*/

Convert json string to date in dd-mm-yy format using javascript [duplicate]

This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 5 years ago.
I want to bind data in a dd-mm-yy format for which I am using json to bind. Currently I get date as 2014-06-18T00:00:00
I want in dd-mm-yy format. Kindly let me know how to do that.
Below is my code for the same.
if (getJSONValue.LAUNCH_DATE != "" || getJSONValue.LAUNCH_DATE == null) {
$('#txtLaunchDate').val(getJSONValue.LAUNCH_DATE);
}
my getJSONValue.LAUNCH_DATE = 2014-06-18T00:00:00
see snippet
var newDate = new Date("2014-06-18T00:00:00");
var day = newDate.getDate();
var month = newDate.getUTCMonth() + 1;
var year = newDate.getFullYear();
console.log(day + "-" + ("0" + (month)) + "-" + year );
Using momentjs:
const date = '2014-06-18T00:00:00'
const format = 'DD-MM-YY'
console.log(moment(date).format(format))
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment.js"></script>

Javascript Date object returning April 31? [duplicate]

This question already has answers here:
javascript is creating date wrong month
(4 answers)
Closed 5 years ago.
There seems to be an error with the Date object in Javascript, it thinks April 31, 2017 is a real day. I discovered this by trying to get the date 90 days ago from today (August 29). The following is a snippet of my code for context:
*Edit: For context, this is in Google Apps Script technically.
var now = new Date();
var ninetyDaysAgo = new Date(now.getTime() - 90 * 1000 * 60 * 60 * 24);
var dateStr = ninetyDaysAgo.getFullYear() + '-' +
ninetyDaysAgo.getMonth() + '-' +
ninetyDaysAgo.getDate();
//If I print dateStr it's '2017-4-31'
This is important because I need the correct date to use an API. Is this just a thing in the date class or am I missing something?
getMonth is zero-based. So you need to use it like below:
var dateStr = ninetyDaysAgo.getFullYear() + '-' +
(ninetyDaysAgo.getMonth() + 1) + '-' +
ninetyDaysAgo.getDate();

date now javascript convert format [duplicate]

This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
Closed 8 years ago.
how to convert timeInMs to this format dd/mm/yyyy
var timeInMs = Date.now();
alert(timeInMs);
//convert to dd/mm/yyy
is there any advantage of using jquery when dealing with time/date?
var date = new Date();
var year = date.getUTCFullYear();
var month = date.getUTCMonth();
var day = date.getUTCDate();
//month 2 digits
month = ("0" + (month + 1)).slice(-2);
//year 2 digits
year = year.toString().substr(2,2);
var formattedDate = day + '/' + month + "/" + year;
prints 25/10/13

formate date in javascript [duplicate]

This question already has answers here:
Where can I find documentation on formatting a date in JavaScript?
(39 answers)
compare todays date with calender date (for next seven days only else generate alert ) [closed]
(2 answers)
Closed 8 years ago.
var mydate = new Date();
var theyear = mydate.getFullYear();
var themonth = mydate.getMonth() + 1;
var thetoday = mydate.getDate();
txtbox.value="04-Jul-2012"
I have to convert todays date and txtbox date in "04/07/2012" format how i do it.
I have to compare todays date with txtbox date.
Thanks
Use date.js javascript library.
http://www.datejs.com/2007/11/27/getting-started-with-datejs/
var d1 = Date.parse('04-Jul-2012');
alert(d1.toString('dd/MM/yyyy'));
Date comparison
var today = Date.today();
var past = Date.today().add(-6).days();
var future = Date.today().add(6).days();
Date.compare(today, future); // -1
Date.compare(today, new Date().clearTime()); // 0
Date.compare(today, past) // 1

Categories

Resources