开发者

Extract day and week number of a specific month given a specific date or time stamp

Preferred in jQuery, if possible, otherwise any Javascript will work.

I开发者_如何学C'd like to get the day and week number of month given a specific date or timestamp.

For example

2010-10-26 would return Tuesday and 4 as the week number

2010-11-11 would return Thursday and 2 as the week number


You need to look into the Javascript date object.

To get the day of the week, you need to do something like the following:

var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];

var myDate = new Date('2010-10-26');

var dayOfWeek = days[myDate.getDay()]; // dayOfWeek == 'Tuesday'

This is because getDay() returns a number 0-6 rather than a string. This is useful e.g. for internationalisation.

Your other requirement (week of month) would need custom coding -- it can't be done using the native JS date object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜