久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何計(jì)算給定日期的周數(shù)?

How do I calculate the week number given a date?(如何計(jì)算給定日期的周數(shù)?)
本文介紹了如何計(jì)算給定日期的周數(shù)?的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

如果我有一個(gè)日期,我如何計(jì)算該日期在那一年中的周數(shù)?

If I have a date, how do I calculate the week number for that date within that year?

例如,在 2008 年,1 月 1 日至 1 月 6 日在第 1 周,而 1 月 7 日至 13 日在第 2 周,因此如果我的日期是 2008 年 1 月 10 日,則我的周數(shù)為 2.

For example, in 2008, January 1st to January 6th are in week 1 and January 7th to the 13th are in week 2, so if my date was January 10th 2008, my week number would be 2.

算法非常適合讓我入門(mén),示例代碼也會(huì)有所幫助 - 我正在 Windows 上使用 C++ 進(jìn)行開(kāi)發(fā).

An algorithm would be great to get me started and sample code would also help - I'm developing in C++ on Windows.

從日期中獲取周數(shù)MS SQL Server 2005?

推薦答案

偽代碼:

int julian = getDayOfYear(myDate)  // Jan 1 = 1, Jan 2 = 2, etc...
int dow = getDayOfWeek(myDate)     // Sun = 0, Mon = 1, etc...
int dowJan1 = getDayOfWeek("1/1/" + thisYear)   // find out first of year's day
// int badWeekNum = (julian / 7) + 1  // Get our week# (wrong!  Don't use this)
int weekNum = ((julian + 6) / 7)   // probably better.  CHECK THIS LINE. (See comments.)
if (dow < dowJan1)                 // adjust for being after Saturday of week #1
    ++weekNum;
return (weekNum)

澄清一下,這個(gè)算法假設(shè)你像這樣計(jì)算你的周數(shù):

To clarify, this algorithm assumes you number your weeks like this:

S  M  T  W  R  F  S
            1  2  3    <-- week #1
4  5  6  7  8  9 10    <-- week #2
[etc.]

getDayOfWeek() 和 getDayOfYear() 是大多數(shù)語(yǔ)言中的標(biāo)準(zhǔn)日期對(duì)象操作.如果您的沒(méi)有它們,您可以從某個(gè)已知日期(1970 年 1 月 1 日是常見(jiàn)的日期)開(kāi)始計(jì)算,然后查看一周中的哪一天.

getDayOfWeek() and getDayOfYear() are standard date-object operations in most languages. If yours doesn't have them, you can count-forward from some known date (Jan 1, 1970 is a common one), after looking up to see what day of the week it was.

如果您要實(shí)現(xiàn)自己的日期計(jì)數(shù)例程,請(qǐng)記住可被 100 整除的年份是不是閏年,除非它們也可被 400 整除.因此 1900 不是閏年年,但 2000 年是.如果您要回到過(guò)去工作很長(zhǎng)時(shí)間,則必須弄亂公歷與儒略歷等,請(qǐng)參閱 維基百科提供大量相關(guān)信息.

If you're going to implement your own date counting routines, remember that years that are divisible by 100 are NOT leap years, unless they are also divisible by 400. So 1900 was not a leap year, but 2000 was. If you're going to work far back in time, you have to mess with Gregorian vs Julian calendars, etc., see Wikipedia for loads of info on that.

此鏈接 更詳細(xì)地討論了 Windows/C++ 中的日期/時(shí)間函數(shù)細(xì)節(jié).

This link talks about date/time functions in Windows/C++ in greater detail.

這篇關(guān)于如何計(jì)算給定日期的周數(shù)?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

boost_1_60_0 .zip installation in windows(Windows 中的 boost_1_60_0 .zip 安裝)
How do I get console output in C++ with a Windows program?(如何使用 Windows 程序在 C++ 中獲得控制臺(tái)輸出?)
OpenCV with Network Cameras(帶有網(wǎng)絡(luò)攝像機(jī)的 OpenCV)
Export all symbols when creating a DLL(創(chuàng)建 DLL 時(shí)導(dǎo)出所有符號(hào))
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門(mén))
The program can#39;t start because libgcc_s_dw2-1.dll is missing(程序無(wú)法啟動(dòng),因?yàn)槿鄙?libgcc_s_dw2-1.dll)
主站蜘蛛池模板: 在线观看国产小视频 | 日日操夜夜爽 | 日韩精品在线观看视频 | av网站免费观看 | 在线日韩| 成人毛片在线观看 | 在线观看免费毛片 | av网站免费观看 | 黄色一级片黄色一级片 | 久久男人| 欧美在线中文字幕 | 中文字幕第一区综合 | 六月激情| 日韩精品国产一区 | 99国产精品99久久久久久粉嫩 | 精品一二区 | 日韩专区在线观看 | 四虎影视在线播放 | 欧美一区二区在线视频 | 黑人精品一区二区 | 欧美一区二区精品 | av不卡在线播放 | 国产欧美日韩在线观看 | 国产中文字幕在线播放 | 日韩久久网 | 国产毛片一级 | 欧美综合网 | 亚洲精品18在线观看 | 久久久久九九九 | 久久久久久久网 | 日韩一级片视频 | 欧美性精品 | 黄www.| 日本成人一区二区 | 国产精品一区av | 国产三级在线看 | 国产精品www | 亚洲精品日韩精品 | 亚洲激情另类 | 欧美亚洲在线 | 香蕉视频一直看一直爽 |