Date format in javascript with time 00:00:00 - javascript

How to get Date Format as
Fri Dec 03 2014 00:00:00 GMT+0530 (IST)
Todays date with time 00:00:00 in javascript ?
Any help appreciated

var myDate = new Date();
myDate.setHours(0,0,0);
alert(myDate);
jsfiddle http://jsfiddle.net/nrud7j8v/2
about javascript setHours() method http://www.w3schools.com/jsref/jsref_setHours...

Related

Convert date/time into timestamp

I want to convert following date and time, into a timestamp 13 digits. Note I use strict mode.
Date:
Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)
Time:
03:00
I tried to use Date.parse() but it was not working. What is the best way to do this?
You can use the getTime function:
console.log(new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)').getTime());
Try below code
console.log(new Date().getTime());
Create the date object, add time as you wish and then use the getTime() function:
"use strict";
var date = new Date('Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)');
date.setHours(parseInt('03'),[parseInt('00')]); //apply hours and minutes
console.log(date.toString());
console.log(date.getTime()); //use of getTime()
console.log(+new Date("Thu Jun 01 2017 00:00:00 GMT+0200 (CEST)"))

How to get date object from date string format

I'm trying to convert a date string to date format, something like this:
var date = "07/11/2015"; //format is mm/dd/yyyy
Now I want it to be in this format:
date = Tue Sep 01 2015 00:00:00 GMT+0530 (India Standard Time)
Can anyone suggest a way to achieve it. Thanks in advance!
var date = "07/11/2015";
alert(new Date(date)); //Sat Jul 11 2015 00:00:00 GMT+0530 (India Standard Time)

javascript date subtract hours - Error

I'm trying to subtract 1 hour from the current date, I'm using this code:
var date = new Date();
// date is **Fri Apr 03 2015 16:47:33 GMT+0100 (GMT Standard Time)**
var uploadDateFilter = new Date(new Date(date).setHours(date.getHours()-1)).toISOString();
//now date is **Fri Apr 03 2015 14:47:33 GMT+0100 (GMT Standard Time)**
There's less two hours instead of just one. What am I missing here?
Your code works when looking at the elements in the same format.
<div class="original"></div>
<div class="updated"></div>
Using jQuery to post the information ... with your code, as is.
$(".original").text(date.toISOString());
$(".updated").text(uploadDateFilter);
Results in ...
2015-04-03T16:00:23.441Z
2015-04-03T15:00:23.441Z
http://jsfiddle.net/rfornal/5nma5uhr/
You don't need .toISOString(), but for me it works :
var date = new Date();
var uploadDateFilter = new Date(new Date(date).setHours(date.getHours()-1));
console.log(date);
console.log(uploadDateFilter);
Console output :
Fri, 03 Apr 2015 15:59:48 GMT
Fri, 03 Apr 2015 14:59:48 GMT
http://repl.it/gxL
The reason appears to be daylight saving check this my fiddle.
For me in the UK the clocks went forward on Mar 29, 2015. Checking the effect of new Date().toISOString() before and after this date, during daylight saving the result is one hour less.

Why is new Date() subtracting 1 day in Javascript?

I need to convert a String to a Date object.
The date string is delivered in the following format:
"2015-01-28T00:00:00"
When I create a new Date, I get the previous date:
Entered: new Date("2015-01-28T00:00:00")
Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
Does anyone know why this is occurring?
When you enter the following:
new Date("2015-01-28T00:00:00");
// Result: Tue Jan 27 2015 17:00:00 GMT-0700 (Mountain Standard Time)
the browser assumes that you are giving a date in GMT Time zone. So it will automatically convert the given date to your local date.
It's always a good idea to inform the browser of the timezone you are working on in order to prevent future problems:
new Date("2015-01-28T00:00:00-07:00");
// Result: Tue Jan 28 2015 00:00:00 GMT-0700 (Mountain Standard Time)
Actually, you aren't getting the previous date . . . you are getting that date, offset by the timezone difference.
Tue Jan 27 2015 17:00:00(Mountain Time) + 7 hours (time zone difference) = 2015-01-28T00:00:00 (GMT)
Or, in English, when it is 12:00 Midnight in Greenwich, England, it is 5:00 PM on the previous day in Denver, Colorado. ;)
It's the right date/time, just in a different timezone.

Converting a date/time string to a date object

I have a string:
"2014-07-30T21:11:35.6300000"
but when I do
new Date(str)
It computes:
Wed Jul 30 2014 17:11:35 GMT-0400 (Eastern Daylight Time)
Q: How do I tell JavaScript not to calculate GMT -0400?
(new Date("2014-07-30T21:11:35.6300000")).toUTCString()

Categories