What's the Current Week Number? - Epoch Converter

文章推薦指數: 80 %
投票人數:10人

2021 has 52 weeks. ISO 8601 is not the only week numbering system in the world, other systems use weeks starting on Sunday (US) or Saturday (Islamic). EpochConverter ☰ What'stheCurrentWeekNumber? Thisweekis...   Week49 Week49isfromMonday,December6,2021until(andincluding)Sunday,December12,2021. WeeknumberaccordingtotheISO-8601standard,weeksstartingonMonday.Thefirstweekoftheyearistheweekthatcontainsthatyear'sfirstThursday(='First4-dayweek'). ISOrepresentation:2021-W49 Thehighestweeknumberinayeariseither52or53.2021has52weeks. ISO8601isnottheonlyweeknumberingsystemintheworld,othersystemsuseweeksstartingonSunday(US)orSaturday(Islamic). Listsofweeknumbersbyyear: 2020- 2021- 2022- 2023... Programmingroutines MicrosoftExcel/LibreOfficeCalc =ISOWEEKNUM(TODAY()) or(inolderversions): =WEEKNUM(TODAY(),21) Wherethereturntype'21'isISO-8601(weekstartingonMonday).InExcel2007yourbestchoiceisWEEKNUM(TODAY(),2)(2=weekstartingMonday). WEEKNUM(TODAY())willshowtheweeknumberwithweeksstartingonSunday(returntype=1). GoogleDocsSpreadsheet =WEEKNUM(TODAY();21) Type(here'21')iscompatiblewithExcel/LibreOffice,21isISO-8601 PHP $weekNumber=date("W"); ordate("W",epoch)forotherweeknumbers.Remembertousecapital'W'not'w'. Python datetime.date.today().isocalendar()[1] PERL my$weekNumber=POSIX::strftime("%V",gmtimetime); Replacetimewithotherepoch/UNIXtimestampsforotherweeknumbers. Java Calendarnow=Calendar.getInstance(); now.get(Calendar.WEEK_OF_YEAR); UseWEEK_OF_YEARintheCalendarclass. MoreinfoonStackOverflow JavaScript Date.prototype.getWeek=function(){ vartarget=newDate(this.valueOf()); vardayNr=(this.getDay()+6)%7; target.setDate(target.getDate()-dayNr+3); varfirstThursday=target.valueOf(); target.setMonth(0,1); if(target.getDay()!=4){ target.setMonth(0,1+((4-target.getDay())+7)%7); } return1+Math.ceil((firstThursday-target)/604800000); } vard=newDate(); alert(d.getWeek()); ExtendtheDateclassusingtheabovecode. C# SeetheISO-8601updateonStackOverflow MySQL SELECTWEEKOFYEAR(NOW()) Replacenow()withotherdateseg.SELECTWEEKOFYEAR('2021-02-20'); (YoucanalsousetheWEEKfunctionwithmode=3selectweek(now(),3)) PostgreSQL SELECT*FROMEXTRACT(WEEKfromcurrent_date()) MSSQL SELECTDATEPART(wk,GETDATE()) Oracle SELECTto_char(sysdate,'IW')FROMDUAL IW:Weekofyear(1-52or1-53)basedontheISO-8601standard. WW:Weekofyear(1-53)whereweek1startsonthefirstdayoftheyearandcontinuestotheseventhdayoftheyear(MostlyNOTused) iSeriesSQL SELECTWEEK(NOW())fromsysibm.sysdummy1 iPhone/Mac [NSStringstringWithFormat:@"Week%d", [calendarordinalityOfUnit:NSWeekCalendarUnitinUnit:NSYearCalendarUnitforDate:date]]; iPhone/iOS/Swift letgregorian=NSCalendar(calendarIdentifier:NSCalendarIdentifierGregorian)! gregorian.firstWeekday=2//Monday gregorian.minimumDaysInFirstWeek=4 letcomponents= gregorian.components(.WeekOfYearCalendarUnit|.YearForWeekOfYearCalendarUnit,fromDate:date) letweek=components.weekOfYear letyear=components.yearForWeekOfYear R lubridate::week() Ruby week_number=Time.now.strftime("%U") ReplaceTime.nowwithTime.local(year,month,day)forotherdates. Formats: %U-Weeknumberoftheyear,startingwiththefirstSundayasthefirstdayofthefirstweek(00..53) %V-WeeknumberofyearaccordingtoISO-8601(01..53) %W-Weeknumberoftheyear,startingwiththefirstMondayasthefirstdayofthefirstweek(00..53) Go year,week:=time.Now().ISOWeek() Linux/Unixshell(bash) date+%V ReturnstheISO-8601weeknumber. Otherformatsunder'Ruby'.MoredetailsintheLinuxProgrammer'sManual Lua Current_week=os.date("%V") Formats:seeformatsunder'Ruby'. WindowsPowerShell Get-Date-UFormat%V #or "{0:d2}"-f($(Get-Culture).Calendar.GetWeekOfYear($(Get-Date), [System.Globalization.CalendarWeekRule]::FirstFourDayWeek,[DayOfWeek]::Monday)) X++(MicrosoftDynamicsAX) intweeknum; weeknum=weekOfYear(today()); C/AL(MicrosoftDynamicsNAV): MESSAGE(FORMAT(CALCDATE('CW',TODAY),0,''));  Thankstoeveryonewhosentmecorrectionsandupdates! Commentsandquestions Showcomments Pages Home Preferences Toggletheme Home-Sitemap-Privacy-Disclaimer-Contact-Twitter-Facebook©2021EpochConverterbyMisja.com Jumptotop



請為這篇文章評分?