In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the common date and time methods of C#". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let Xiaobian take you to learn "what are the common date and time methods of C#"!
January and Month English Abbreviations
DateTime dt = DateTime.Now;string MM = dt.AddMonths(-1).ToString("MMM", new System.Globalization.CultureInfo("en-us"));//Month English abbreviation: Jul
First and last day of the month
DateTime ThisMonth_Frist = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date;DateTime ThisMOnth_Last = DateTime.Now.AddDays(1 - DateTime.Now.Day).Date.AddMonths(1).AddSeconds(-1);
Third, the first and last day of last month
DateTime Today = DateTime.Today;//DateTime ThisMonth = new DateTime(Today.Year, Today.Month, 1);//DateTime LastMonth_First = ThisMonth.AddMonths(-1);//DateTime LastMonth_Last = ThisMonth.AddDays(-1);//DateTime Last Day of Last Month
4. Days of the week
int daysInWeek1 = (int)DateTime.Now.DayOfWeek;//Note: Week, DayTime returns 0 here, int daysInWeek2 = (int)DateTime.Now.DayOfWeek == 0 ? 7 : (int)DateTime.Now.DayOfWeek;//the day of the week, note: Sunday is 0
V. Weeks of the month
int a = WeekOfMonth(DateTime.Now, false);//
6. Weeks of the year
private int WeekOfYear() { var dt = DateTime.Now; int firstWeekend = Convert.ToInt32(DateTime.Parse(dt.Year + "-1-1").DayOfWeek); int weekDay = firstWeekend == 0 ? 1 : (7 - firstWeekend + 1); int currentDay = dt.DayOfYear; int current_week = Convert.ToInt32(Math.Ceiling((currentDay - weekDay) / 7.0)) + 1; return current_week; }
7. Mondays and Sundays in previous weeks
private void FEDayInLastWeek() { int N = 3;//parameters of previous weeks DateTime Today = DateTime.Now; int daysInWeek = (int)Today.DayOfWeek == 0 ? 7 : (int)Today.DayOfWeek;//the day of the current week, note: Sunday is 0 for (int i = N; i > 0; i--) { //Start Date DateTime firstDay = Today.AddDays(1 - (7 * i + daysInWeek)); DateTime lastDay = Today.AddDays(7 - (7 * i + daysInWeek)); } }
8. This Monday and the Current Day
private void FristDayToNowInThisWeek() { int daysInWeek = (int)DateTime.Now.DayOfWeek == 0 ? 7 : (int)DateTime.Now.DayOfWeek;//the day of the week, note: Sunday is 0 //Start Date DateTime firstDay = DateTime.Now.AddDays(1 - daysInWeek); DateTime lastDay = DateTime.Now; }
C#controls bind time field formatting
Bind("queried fields", "{0: yy/MM/dd}") At this point, I believe everyone has a deeper understanding of "what are the common date and time methods of C#". You may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.