Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement common time format in C #

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "how to realize common time format in C#". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how to realize common time format in C#" can help you solve the problem.

The code is as follows:

string aa = DateTime.Now.ToShortDateString();//"2019/9/23"string bb = DateTime.Now.ToShortTimeString();//"10:21 AM"string ff = DateTime.Now.ToLongDateString();//September 23, 2019 string gg = DateTime.Now.ToLongTimeString();//10:22:07 AM int monthDays = DateTime.DaysInMonth (DateTime.Now.Year, DateTime.Now.Month);//Gets the number of days of a month in a year DateTime From = DateTime.ParseExact (/*tdFrom.Text*/"201909", "yyyyMM", DateTimeFormatInfo.InvariantInfo);//String to DatetimeDateTime End = DateTime.ParseExact (/*tdEnd.Text*/"201909", "yyyyMM", DateTimeFormatInfo.InvariantInfo);string nian = DateTime.Now.ToString("Y");//Sep 2019 string nian1 = DateTime.Now.ToString("y");//Sep 2019 string y1 = DateTime.Now.ToString("R");//Mon, 23 Sep 2019 10:31:48 GMTstring y2 = DateTime.Now.ToString("r");//Mon, 23 Sep 2019 10:32:10 GMTstring xingqiji = DateTime.Now.ToString("dddd");// "DateTime.Now.ToString("ddd");// " Monday "string ri = DateTime. Now. ToString ("dd");// 23string ershisi = DateTime. Now. ToString("HH"); //3string shier = DateTime. Now.ToString("hh");//15string chang = DateTime.Now.ToString("F");//Sep 23, 2019 10:34:08string chang1 = DateTime.Now.ToString("f");/Sep 23, 2019 10:34string cahng2 = DateTime.Now.ToString("G");//Sep 23, 2019 10:35:07string cahng3 = DateTime.Now.ToString("g");/Sep 23, 2019 10:35string cahng4 = DateTime.Now.ToString("D");//Sep 23, 2019 string cahng5 = DateTime.Now.ToString("d");//2019/9/23string now = DateTime.Now.ToString ("yyyy/MM/dd HH:mm:ss");//2019/09/23 10:14:54string a = DateTime.Now.AddYears(20).ToString ("yyyy/MM/dd HH:mm:ss");//2039/09/23 10:14:54string b = DateTime.Now.AddMonths(-2).ToString ("yyyy/MM/dd HH:mm:ss");//"2019/07/23 10:14:54"string c = DateTime.Now.AddDays(-8).ToString ("yyyy/MM/dd HH:mm:ss");//"2019/09/15 10:14:54"string d = DateTime.Now.AddHours(24).ToString ("yyyy/MM/dd HH:mm:ss");//"2019/09/24 10:14:54"string f = DateTime.Now.AddMinutes(1440).ToString ("yyyy/MM/dd HH:mm:ss");//2019/09/24 10:14:54string g = DateTime.Now.AddSeconds(3600).ToString ("yy/MM/dd HH:mm:ss");//2019/09/23 11:14:54"string h = DateTime.Now.AddSeconds(3600).ToString(" yyy/MM/dd HH:mm:ss:ffff");//2019/09/23 11:14:54:7992 That's all about" How to implement common time format for C#". Thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.

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: 225

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report