Get or convert Week of year to ISO week - Stack Overflow

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

Your original post does not mention you are looking for ISO week, which may have made what you want unclear. The NET GetWeekOfYear using ... Home Public Questions Tags Users Collectives ExploreCollectives FindaJob Jobs Companies Teams StackOverflowforTeams –Collaborateandshareknowledgewithaprivategroup. CreateafreeTeam WhatisTeams? Teams CreatefreeTeam CollectivesonStackOverflow Findcentralized,trustedcontentandcollaboratearoundthetechnologiesyouusemost. Learnmore Teams Q&Aforwork Connectandshareknowledgewithinasinglelocationthatisstructuredandeasytosearch. Learnmore GetorconvertWeekofyeartoISOweek AskQuestion Asked 6years,11monthsago Active 22daysago Viewed 3ktimes 4 WhiletryingtogetthenumberofweeksinayearItriedthis: maxWeek=calendar.GetWeekOfYear(NewDate(t_year,12,31), CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday) Whichdidn'tworkwellformypurpouse,butInoticedsomethingweird.For2014-12-31itreturned53andfor2015-01-01itreturned1.For2015-01-05itreturned2.Thatmeansthattheweeks53and1aresmallerthen7days! IneedtheresulttobeISOWeekcompliant.Icouldn'tfindonlineanyexamplesofcalendarsfollowingthissamelogic.Themallshowtheweek1asfrom2014-12-29to2015-01-04. vb.net Share Improvethisquestion Follow editedJan11'15at16:20 ŇɏssaPøngjǣrdenlarp 37.6k1111goldbadges5454silverbadges157157bronzebadges askedJan2'15at16:06 mathiasfkmathiasfk 1,1521818silverbadges3535bronzebadges 2 2 YouareaskingforCalendarWeekRule.FirstFourDayWeek.Ifyoudon'tliketheresult,trytheotheroptions. – GSerg Jan2'15at16:12 @GSergIndeedItriedThisotherrules,butanyreturned01fromthe29thofdecember,asIwouldexpectISOweek.BywhatIseeontheexamplesonthismsdnpagethereisnorulecompatiblewithwhatIwant. – mathiasfk Jan2'15at16:36 Addacomment  |  2Answers 2 Active Oldest Votes 7 YouroriginalpostdoesnotmentionyouarelookingforISOweek,whichmayhavemadewhatyouwantunclear. TheNETGetWeekOfYearusingFirstFourDayWeekandDayOfWeek.MondayisalmostlikeanISOWeek.ThedifferenceisthatanISOWeekisalwayssevendays.KeepinmindthatanISODateisnotjustadifferentformat,butadifferentcalendarcompletewithitsownterms(likeleapweek).YourdefaultNETcalandarontheotherhandisGregorian. ItisnothardtotweakaNETWOYtoanISOWeek: PublicSharedFunctionGetISOWeekOfYear(dtAsDateTime)AsInteger DimcalAsCalendar=CultureInfo.InvariantCulture.Calendar DimdAsDayOfWeek=cal.GetDayOfWeek(dt) If(d>=DayOfWeek.Monday)AndAlso(d<=DayOfWeek.Wednesday)Then dt=dt.AddDays(3) EndIf Returncal.GetWeekOfYear(dt,CalendarWeekRule.FirstFourDayWeek,DayOfWeek.Monday) EndFunction Simpletesterfor12/31/xxxx: FornAsInteger=1990To2016 Console.WriteLine("{0}:week:{1}",n.ToString, GetISOWeekOfYear(NewDateTime(n,12,31)).ToString) Next Outputofjustthelastfew: 2005:week:52 2006:week:52 2007:week:1 2008:week:1 2009:week:53 2010:week:52 2011:week:52 2012:week:1 2013:week:1 2014:week:1 2015:week:53 2016:week:52 Share Improvethisanswer Follow editedJan6'15at15:40 answeredJan6'15at2:41 ŇɏssaPøngjǣrdenlarpŇɏssaPøngjǣrdenlarp 37.6k1111goldbadges5454silverbadges157157bronzebadges 2 Thanks,thisseemstowork!Youareright,IshouldhavementionedinthepostthatIwaslookingfortheISOweek. – mathiasfk Jan6'15at15:56 UnbelievablehowcrazyitisjusttogetaweeknumberthatsISOcompliant.Thanksforthis. – DreamTeK May17'16at15:36 Addacomment  |  0 Trythis: DimmaxWeekAsInteger=Globalization.ISOWeek.GetWeekOfYear(NewDate(t_year,12,31)) Appliesto.NETversions:.NET5,.NET6,.NETCore3.0,.NETCore3.1and.NETStandard2.1 GetDetailshere: https://docs.microsoft.com/en-us/dotnet/api/system.globalization.isoweek.getweekofyear?view=net-6.0 Share Improvethisanswer Follow editedNov19at8:06 buddemat 2,90299goldbadges1212silverbadges3434bronzebadges answeredNov19at7:55 AreMohAreMoh 111bronzebadge Addacomment  |  YourAnswer ThanksforcontributingananswertoStackOverflow!Pleasebesuretoanswerthequestion.Providedetailsandshareyourresearch!Butavoid…Askingforhelp,clarification,orrespondingtootheranswers.Makingstatementsbasedonopinion;backthemupwithreferencesorpersonalexperience.Tolearnmore,seeourtipsonwritinggreatanswers. Draftsaved Draftdiscarded Signuporlogin SignupusingGoogle SignupusingFacebook SignupusingEmailandPassword Submit Postasaguest Name Email Required,butnevershown PostYourAnswer Discard Byclicking“PostYourAnswer”,youagreetoourtermsofservice,privacypolicyandcookiepolicy Nottheansweryou'relookingfor?Browseotherquestionstaggedvb.netoraskyourownquestion. TheOverflowBlog Smashingbugstosetaworldrecord:AWSBugBust Podcast399:ZerotoMVPwithoutprovisioningadatabase FeaturedonMeta Reducingtheweightofourfooter NewresponsiveActivitypage Communityinputneeded:Therulesforcollectivesarticles A/BtestingontheAskpage Linked 5 VB.NETDatetimePicker-Wrongweeknumber Related 572 HowdoyougetastringfromaMemoryStream? 0 vb.net-Howtogetthedaynumberfromaweekdayname 2 Gettingallofaspecificdaybetweentwodates-quickestmethod? 0 Howtotakethedateofthelastsaturdayforeverynextyearofagivenstartdate 1 GettheDateofMonthsWeekNumber 3 'Shape-append'queriesequivalencenowdays 5 IncorrectISO8601WeekNumberusingDatePart() 1 VB.NETComparedates,days,weekstobuildnewdatetimevariable 1 Getweeknumberbyyearandmonth 0 CrystalreportsuddenlyprintingDetailssectionTwice HotNetworkQuestions Usingecho""tocreateanewemptyfileisn'tcreatinganemptyfile RevoltofThirdWorld;SouthAfricangoldminesnuked Takingconstantoutofindefiniteintegrals Howtomaketheperfectpizzashapefromacircleusingthepentool? Whycan'taconstmutablelambdawithanauto&parameterbeinvoked? Whatisthepurposeofacarriersignalincommunicationtechnology? Whydopresidentsreceiveapensionaftertheirtermofoffice? WhydoesTritonesoundgoodinLydianscale? IfIgetapositiveresponseonaCovid-19testforthepurposeoftravellingtotheUSA,andthendoanotherandgetanegative,canIusethatone? AoCG2021Day10:Memoryreallocationroutine IsthereanodecalledSplineParameterinBlender3.0? Arethereanyregulations,standardsorguidelinescoveringchecklisttypesetting,content,etc.? Howcanamoonbealwaysfull(nootherphases)? FillingGridPointsIntersectedbyaCircle WhattoavoidwhenwritingdistantandinconsequentialPOVs? IsencryptingeverynumberseparatelyusingRSAsecure? Isitacrimetohavechildoutsideofwedlock? Groupalistofpairsbasedonthepaththeymake cunnilingusvscunnilinctus Authorshipofastudentwhopublishedseparatelywithoutpermission Changingchordsinjazz Findingtheresonancefrequencyforforceddampedoscillations AoCG2021Day11:Garbagefulstreams Areallfreeultrafilters'thesame'insomesense? morehotquestions Questionfeed SubscribetoRSS Questionfeed TosubscribetothisRSSfeed,copyandpastethisURLintoyourRSSreader. lang-vb Yourprivacy Byclicking“Acceptallcookies”,youagreeStackExchangecanstorecookiesonyourdeviceanddiscloseinformationinaccordancewithourCookiePolicy. Acceptallcookies Customizesettings  



請為這篇文章評分?