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

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

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

問題描述

如果我有一個日期,我如何計算該日期在那一年中的周數(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.

算法非常適合讓我入門,示例代碼也會有所幫助 - 我正在 Windows 上使用 C++ 進(jìn)行開發(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)

澄清一下,這個算法假設(shè)你像這樣計算你的周數(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ù)語言中的標(biāo)準(zhǔn)日期對象操作.如果您的沒有它們,您可以從某個已知日期(1970 年 1 月 1 日是常見的日期)開始計算,然后查看一周中的哪一天.

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.

如果您要實現(xiàn)自己的日期計數(shù)例程,請記住可被 100 整除的年份是不是閏年,除非它們也可被 400 整除.因此 1900 不是閏年年,但 2000 年是.如果您要回到過去工作很長時間,則必須弄亂公歷與儒略歷等,請參閱 維基百科提供大量相關(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ù)細(xì)節(jié).

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

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

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(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++ 中獲得控制臺輸出?)
OpenCV with Network Cameras(帶有網(wǎng)絡(luò)攝像機(jī)的 OpenCV)
Export all symbols when creating a DLL(創(chuàng)建 DLL 時導(dǎo)出所有符號)
Getting started with OpenCV 2.4 and MinGW on Windows 7(Windows 7 上的 OpenCV 2.4 和 MinGW 入門)
The program can#39;t start because libgcc_s_dw2-1.dll is missing(程序無法啟動,因為缺少 libgcc_s_dw2-1.dll)
主站蜘蛛池模板: 亚洲视频在线看 | 久久久蜜臀国产一区二区 | 91一区二区 | 精品国产黄a∨片高清在线 成人区精品一区二区婷婷 日本一区二区视频 | 国产成人精品免费视频大全最热 | 日韩免费三级 | 欧美日韩亚洲二区 | 91av视频在线观看 | 亚洲精品二区 | 国产高潮av| 天天色图 | 日本高清视频在线播放 | 亚洲成人国产综合 | 亚洲午夜精品视频 | 久久精品视频在线播放 | 国产免费视频 | 在线黄av| 一级一级毛片免费看 | 久久国产成人 | 欧美亚洲在线 | 天天干狠狠干 | 国产永久免费 | 在线免费黄色小视频 | 亚洲精品久久久久久久久久久 | 日韩精品一区二区三区久久 | 看片一区 | 欧美久久综合 | 欧美成人二区 | 亚洲综合精品 | 亚洲欧洲精品一区 | 成人在线视频网站 | 成人国产一区二区三区精品麻豆 | 成人免费视频观看 | 亚洲成人高清 | 国产亚洲精品久久久久久豆腐 | 日韩中文字幕 | 午夜成人免费视频 | 亚洲精品国产电影 | 一级黄色毛片免费 | 视频三区 | 韩国精品一区二区三区 |