How do you know that a date is the first year?

xiaoxiao2021-03-06  22

Idea: Just know that DateTime.dayofyear is also said that this day is the day in the year.

In the beginning of the year, the number of days in the year is the number of days, can calculate the datetime.dayofyear-x / 7 1 is both a number of weeks.

The number of days in the early days of the year can be obtained by DateTime.dayofweek (setting to date from January 1).

This is the specific implementation of the algorithm, it is easy? //

Method 1: Private Int Calcweekofyear (DateTime Today) {DateTime First = Today.Adddays (-1 * Today.dayofyear 1); // Return (Today.dayofyear 7 - Convert.Toint 32 (First.dayofweek) / 7 1; return (Today.dayofyear - Convert.Toint32 (First.dayofweek) / 7 1;} ///

Method 2: USING SYSTEM.GLOBALIZATION;

.......

/ / Get cultureInfo myci = new cultureInfo ("zh-cn"); system.globalization.calendar mycal = myci.calendar;

// Date format Calendarweekrule mycwr = myci.datetimeformat.calendarweekrule; dayofweek myfirstdow = myci.datetimeformat.firstdayofweek;

// This week is the first mycal.getweekofyear (datetime.now, mycwr, myfirstdow) Int thisweek = mycal.getweekofyear (DateTime.now, mycwr, myfirstdow);

转载请注明原文地址:https://www.9cbs.com/read-43363.html

New Post(0)