I have a date in this formate "YYYY/MM/DD". Now I want to get the day from this format. How can I get it using javascript or jquery? One way is this
$(document).ready(function() {
var d = new Date();
alert(d.getDay());
} );
but the problem here is that d variable contains date in this format
Sat Jan 07 2012 18:16:57 GMT+0200 (FLE Standard Time)
How can I get day from date in above format?
Here is how my function look like
function dayOfWeek(d) {
var dayNames = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Sunday');
var currentDate = Math.round(+new Date(d)/1000);
var nData = new Date(currentDate);
//alert(nData);
//alert(nData.getDay());
//var day = d.split("-")[2];
//var t = day.replace("0","");
//alert(t);
return dayNames[nData.getDay()];
}
What I am doing is I am passing date in "YYYY-MM-DD" format and it converts that date to unix timestamp and then I get the day and then return the day as Sunday or Monday etc. But here it only returns Friday which is incorrect. When I change the day in date it should return the same day in array.
the problem here is that d variable contains date in this format: Sat Jan 07 2012 18:16:57 GMT+0200 (FLE Standard Time); nah -- consider it as storing the date in some internal binary format. It only looks like that by default when you stringize it.