I am looking for javascript code which will give me 1st date of the current month according to local timezone (client browser timezone).
Currently I am using the code below:
var startDate =new Date (2012,5,1);
Which correctly gives me this value:
Fri Jun 1 00:00:00 EDT 2012
But when I try the same thing in a browser in Beirut, which is +2.00 GMT, it gives May 31st "at times" (meaning if I try in the morning it gives me 31st but Beriut PM time works fine)
Basically I need to get a local browser current 1st date. Any suggestions?
Calling the Date function without parameters, always return the current time for the browser, which takes the time and timezone from the OS.
Try this:
var now = new Date(),
first = new Date(now.getFullYear(), now.getMonth(), 1);
alert(first);
You can try to see the time zone using now.getTimezoneOffset();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With