目录
Home
DateTime 格式化 / 日期转化
string _time = dateTime1.ToString("yyyy-MM-dd HH:mm:ss");
C#中的DateTime是一个对象,它拥有许多自己的属性和方法,呵,这又是要专门用一篇文章来解释的东西, 我们现在只需了解DateTime拥有这三个方法即可: ToString()、ToShortDateString()、ToShortTimeString()。 这三个方法是DateTime身上最常用的东西, ToString()获得的东西类似于2009-09-10 14:51:32; ToShortDateString()则类似于2009-09-10; ToShortTimeString()的类似于14:51:32。
C#日期格式化 日期转化一 为了达到不同的显示效果有时,我们需要对时间进行转化,默认格式为:2007-01-03 14:33:34 ,要转化为其他格式,要用到DateTime.ToString的方法(String, IFormatProvider),如下所示:
using System; using System.Globalization; String format="D"; DateTime date=DataTime,Now; Response.Write(date.ToString(format, DateTimeFormatInfo.InvariantInfo));
结果输出
Thursday, June 16, 2005
参数format格式详细用法:
格式字符 关联属性/说明 d ShortDatePattern D LongDatePattern f 完整日期和时间(长日期和短时间) F FullDateTimePattern(长日期和长时间) g 常规(短日期和短时间) G 常规(短日期和长时间) m、M MonthDayPattern r、R RFC1123Pattern s 使用当地时间的 SortableDateTimePattern(基于 ISO 8601) t ShortTimePattern T LongTimePattern u UniversalSortableDateTimePattern 用于显示通用时间的格式 U 使用通用时间的完整日期和时间(长日期和长时间) y、Y YearMonthPattern
下表列出了可被合并以构造自定义模式的模式。这些模式是区分大小写的;例如,识别“MM”,但不识别“mm”。如果自定义模式包含空白字符或用单引号括起来的字符,则输出字符串页也将包含这些字符。未定义为格式模式的一部分或未定义为格式字符的字符按其原义复制。 格式模式 说明
d 月中的某一天。一位数的日期没有前导零。 dd 月中的某一天。一位数的日期有一个前导零。 ddd 周中某天的缩写名称,在 AbbreviatedDayNames 中定义。 dddd 周中某天的完整名称,在 DayNames 中定义。 M 月份数字。一位数的月份没有前导零。 MM 月份数字。一位数的月份有一个前导零。 MMM 月份的缩写名称,在 AbbreviatedMonthNames 中定义。 MMMM 月份的完整名称,在 MonthNames 中定义。 y 不包含纪元的年份。如果不包含纪元的年份小于 10,则显示不具有前导零的年份。 yy 不包含纪元的年份。如果不包含纪元的年份小于 10,则显示具有前导零的年份。 yyyy 包括纪元的四位数的年份。 gg 时期或纪元。如果要设置格式的日期不具有关联的时期或纪元字符串,则忽略该模式。 h 12 小时制的小时。一位数的小时数没有前导零。 hh 12 小时制的小时。一位数的小时数有前导零。 H 24 小时制的小时。一位数的小时数没有前导零。 HH 24 小时制的小时。一位数的小时数有前导零。 m 分钟。一位数的分钟数没有前导零。 mm 分钟。一位数的分钟数有一个前导零。 s 秒。一位数的秒数没有前导零。 ss 秒。一位数的秒数有一个前导零。 f 秒的小数精度为一位。其余数字被截断。 ff 秒的小数精度为两位。其余数字被截断。 fff 秒的小数精度为三位。其余数字被截断。 ffff 秒的小数精度为四位。其余数字被截断。 fffff 秒的小数精度为五位。其余数字被截断。 ffffff 秒的小数精度为六位。其余数字被截断。 fffffff 秒的小数精度为七位。其余数字被截断。 t 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项的第一个字符(如果存在)。 tt 在 AMDesignator 或 PMDesignator 中定义的 AM/PM 指示项(如果存在)。 z 时区偏移量(“+”或“-”后面仅跟小时)。一位数的小时数没有前导零。例如,太平洋标准时间是“-8”。 zz 时区偏移量(“+”或“-”后面仅跟小时)。一位数的小时数有前导零。例如,太平洋标准时间是“-08”。 zzz 完整时区偏移量(“+”或“-”后面跟有小时和分钟)。一位数的小时数和分钟数有前导零。例如,太平洋标准时间是“-08:00”。 : 在 TimeSeparator 中定义的默认时间分隔符。 / 在 DateSeparator 中定义的默认日期分隔符。 % c 其中 c 是格式模式(如果单独使用)。如果格式模式与原义字符或其他格式模式合并,则可以省略“%”字符。 \ c 其中 c 是任意字符。照原义显示字符。若要显示反斜杠字符,请使用“\\”。 只有上面第二个表中列出的格式模式才能用于创建自定义模式;在第一个表中列出的标准格式字符不能用于创建自定义模式。自定义模式的长度至少为两个字符;例如, DateTime.ToString( "d") 返回 DateTime 值;“d”是标准短日期模式。 DateTime.ToString( "%d") 返回月中的某天;“%d”是自定义模式。 DateTime.ToString( "d ") 返回后面跟有一个空白字符的月中的某天;“d”是自定义模式。
比较方便的是,上面的参数可以随意组合,并且不会出错,多试试,肯定会找到你要的时间格式 如要得到2005年06月 这样格式的时间 可以这样写:
date.ToString("yyyy年MM月", DateTimeFormatInfo.InvariantInfo)
日期转化二
DateTime dt = DateTime.Now; Label1.Text = dt.ToString();//2005-11-5 13:21:25 Label2.Text = dt.ToFileTime().ToString();//127756416859912816 Label3.Text = dt.ToFileTimeUtc().ToString();//127756704859912816 Label4.Text = dt.ToLocalTime().ToString();//2005-11-5 21:21:25 Label5.Text = dt.ToLongDateString().ToString();//2005年11月5日 Label6.Text = dt.ToLongTimeString().ToString();//13:21:25 Label7.Text = dt.ToOADate().ToString();//38661.5565508218 Label8.Text = dt.ToShortDateString().ToString();//2005-11-5 Label9.Text = dt.ToShortTimeString().ToString();//13:21 Label10.Text = dt.ToUniversalTime().ToString();//2005-11-5 5:21:25 Label1.Text = dt.Year.ToString();//2005 Label2.Text = dt.Date.ToString();//2005-11-5 0:00:00 Label3.Text = dt.DayOfWeek.ToString();//Saturday Label4.Text = dt.DayOfYear.ToString();//309 Label5.Text = dt.Hour.ToString();//13 Label6.Text = dt.Millisecond.ToString();//441 Label7.Text = dt.Minute.ToString();//30 Label8.Text = dt.Month.ToString();//11 Label9.Text = dt.Second.ToString();//28 Label10.Text = dt.Ticks.ToString();//632667942284412864 Label11.Text = dt.TimeOfDay.ToString();//13:30:28.4412864 Label1.Text = dt.ToString();//2005-11-5 13:47:04 Label2.Text = dt.AddYears(1).ToString();//2006-11-5 13:47:04 Label3.Text = dt.AddDays(1.1).ToString();//2005-11-6 16:11:04 Label4.Text = dt.AddHours(1.1).ToString();//2005-11-5 14:53:04 Label5.Text = dt.AddMilliseconds(1.1).ToString();//2005-11-5 13:47:04 Label6.Text = dt.AddMonths(1).ToString();//2005-12-5 13:47:04 Label7.Text = dt.AddSeconds(1.1).ToString();//2005-11-5 13:47:05 Label8.Text = dt.AddMinutes(1.1).ToString();//2005-11-5 13:48:10 Label9.Text = dt.AddTicks(1000).ToString();//2005-11-5 13:47:04 Label10.Text = dt.CompareTo(dt).ToString();//0 Label11.Text = dt.Add(?).ToString();//问号为一个时间段 Label1.Text = dt.Equals("2005-11-6 16:11:04").ToString();//False Label2.Text = dt.Equals(dt).ToString();//True Label3.Text = dt.GetHashCode().ToString();//1474088234 Label4.Text = dt.GetType().ToString();//System.DateTime Label5.Text = dt.GetTypeCode().ToString();//DateTime Label1.Text = dt.GetDateTimeFormats('s')[0].ToString();//2005-11-05T14:06:25 Label2.Text = dt.GetDateTimeFormats('t')[0].ToString();//14:06 Label3.Text = dt.GetDateTimeFormats('y')[0].ToString();//2005年11月 Label4.Text = dt.GetDateTimeFormats('D')[0].ToString();//2005年11月5日 Label5.Text = dt.GetDateTimeFormats('D')[1].ToString();//2005 11 05 Label6.Text = dt.GetDateTimeFormats('D')[2].ToString();//星期六 2005 11 05 Label7.Text = dt.GetDateTimeFormats('D')[3].ToString();//星期六 2005年11月5日 Label8.Text = dt.GetDateTimeFormats('M')[0].ToString();//11月5日 Label9.Text = dt.GetDateTimeFormats('f')[0].ToString();//2005年11月5日 14:06 Label10.Text = dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06 Label11.Text = dt.GetDateTimeFormats('r')[0].ToString();//Sat, 05 Nov 2005 14:06:25 GMT Label1.Text = string.Format("{0:d}",dt);//2005-11-5 Label2.Text = string.Format("{0:D}",dt);//2005年11月5日 Label3.Text = string.Format("{0:f}",dt);//2005年11月5日 14:23 Label4.Text = string.Format("{0:F}",dt);//2005年11月5日 14:23:23 Label5.Text = string.Format("{0:g}",dt);//2005-11-5 14:23 Label6.Text = string.Format("{0:G}",dt);//2005-11-5 14:23:23 Label7.Text = string.Format("{0:M}",dt);//11月5日 Label8.Text = string.Format("{0:R}",dt);//Sat, 05 Nov 2005 14:23:23 GMT Label9.Text = string.Format("{0:s}",dt);//2005-11-05T14:23:23 Label10.Text string.Format("{0:t}",dt);//14:23 Label11.Text = string.Format("{0:T}",dt);//14:23:23 Label12.Text = string.Format("{0:u}",dt);//2005-11-05 14:23:23Z Label13.Text = string.Format("{0:U}",dt);//2005年11月5日 6:23:23 Label14.Text = string.Format("{0:Y}",dt);//2005年11月 Label15.Text = string.Format("{0}",dt);//2005-11-5 14:23:23 Label16.Text = string.Format("{0:yyyyMMddHHmmssffff}",dt);
Welcome to your new DokuWiki
Congratulations, your wiki is now up and running. Here are a few more tips to get you started.
Enjoy your work with DokuWiki,
– the developers
Create your first pages
Your wiki needs to have a start page. As long as it doesn't exist, this link will be red: start.
Go on, follow that link and create the page. If you need help with using the syntax you can always refer to the syntax page.
You might also want to use a sidebar. To create it, just edit the sidebar page. Everything in that page will be shown in a margin column on the side. Read our FAQ on sidebars to learn more.
Please be aware that not all templates support sidebars.
Customize your Wiki
Once you're comfortable with creating and editing pages you might want to have a look at the configuration settings (be sure to login as superuser first).
You may also want to see what plugins and templates are available at DokuWiki.org to extend the functionality and looks of your DokuWiki installation.
Join the Community
DokuWiki is an Open Source project that thrives through user contributions. A good way to stay informed on what's going on and to get useful tips in using DokuWiki is subscribing to the newsletter.
The DokuWiki User Forum is an excellent way to get in contact with other DokuWiki users and is just one of the many ways to get support.
Of course we'd be more than happy to have you getting involved with DokuWiki.
评论
I'd suggest this article to everyone curious about this field. Clear descriptions of important ideas. 1xbet
I'd suggest this article to everyone curious about this field. Clear descriptions of important ideas. 1xbet
I completely concur with your main argument. Additionally, I would add that this aspect is equally important. 1xbet
I completely concur with your main argument. Additionally, I would add that this aspect is equally important. 1xbet
mostbet РФ Your fortune awaits! Enjoy exclusive bonuses! Stay tuned for special events! Subscribe to our newsletter for more! Play big! Tell your colleagues about us! Huge thanks for being part of us! Very professional! Our site is fantastic! Following your latest events! Liked and registered! You're an undisputed expert! Will share with on social media! Thank you for your assistance! Very rewarding experience! Your efforts always lead to wins! mostbet играть mostbet Кыргызстан mostbet mostbet kz
mostbet РФ Your fortune awaits! Enjoy exclusive bonuses! Stay tuned for special events! Subscribe to our newsletter for more! Play big! Tell your colleagues about us! Huge thanks for being part of us! Very professional! Our site is fantastic! Following your latest events! Liked and registered! You're an undisputed expert! Will share with on social media! Thank you for your assistance! Very rewarding experience! Your efforts always lead to wins! mostbet играть mostbet Кыргызстан mostbet mostbet kz
mostbet Azərbaycan Hit the jackpot with us! Unlock your fortune! Play with ease on our licensed platform! Don't miss out on huge jackpots! Win big! Share the joy with friends! Grateful for your loyalty! Simply fantastic! Your efforts always result in victories! Eagerly awaiting your upcoming tournaments! Bookmarked your content in my browser! You're the best! Telling everyone! Thanks for the rewarding experience! Very exciting promotion! Your skills always are rewarded! mostbet ru mostbet mostbet today mostbet Киргизия
mostbet Azərbaycan Hit the jackpot with us! Unlock your fortune! Play with ease on our licensed platform! Don't miss out on huge jackpots! Win big! Share the joy with friends! Grateful for your loyalty! Simply fantastic! Your efforts always result in victories! Eagerly awaiting your upcoming tournaments! Bookmarked your content in my browser! You're the best! Telling everyone! Thanks for the rewarding experience! Very exciting promotion! Your skills always are rewarded! mostbet ru mostbet mostbet today mostbet Киргизия
¡La fortuna te acompaña! No pierdas la oportunidad de disfrutar de apuestas seguros y entretenidas en 1Win. 1win
¡La fortuna te acompaña! No pierdas la oportunidad de disfrutar de apuestas seguros y entretenidas en 1Win. 1win
Discover Bet9ja: The Best Betting Experience in Nigeria!
bet9ja old mobile Looking for a simple betting experience? Access the Bet9ja Old Mobile version and experience fast loading times and easy navigation. Bet on soccer, casino games, and virtual races without the complexities of the new version. Start betting in minutes!
old bet9ja
Discover Bet9ja: The Best Betting Experience in Nigeria!
bet9ja old mobile Looking for a simple betting experience? Access the Bet9ja Old Mobile version and experience fast loading times and easy navigation. Bet on soccer, casino games, and virtual races without the complexities of the new version. Start betting in minutes!
old bet9ja
Pinco Casino'da eğlence sizi bekliyor! pinco
Pinco Casino'da hızla kayıt olabilirsiniz. Bonuslu oyunlar ve yüksek ödeme oranları ile oyun deneyiminizi zenginleştirin. pinco
Pinco Casino'da eğlence sizi bekliyor! pinco
Pinco Casino'da hızla kayıt olabilirsiniz. Bonuslu oyunlar ve yüksek ödeme oranları ile oyun deneyiminizi zenginleştirin. pinco
Exciting casino options await you at Pin-Up! At Pin-Up Casino, you'll find engaging slot games, table games, sports wagers, and much more. Play premium games from top providers like NetEnt and Microgaming, and take your chance for huge wins!
pin up casino india Maximizing the ?450000 Welcome Bonus at Pin-Up Casino. The Pin Up casino welcome offer of up to ?450000 is generous, but how can you take full advantage of it? Have you received this offer yet? Let us know your strategies and tips for transforming the bonus into huge payouts. Let’s talk about how to make the most out of your first top-up!
Exciting casino options await you at Pin-Up! At Pin-Up Casino, you'll find engaging slot games, table games, sports wagers, and much more. Play premium games from top providers like NetEnt and Microgaming, and take your chance for huge wins!
pin up casino india Maximizing the ?450000 Welcome Bonus at Pin-Up Casino. The Pin Up casino welcome offer of up to ?450000 is generous, but how can you take full advantage of it? Have you received this offer yet? Let us know your strategies and tips for transforming the bonus into huge payouts. Let’s talk about how to make the most out of your first top-up!
Use Taya365 bonuses for maximum victories taya365 app Uncover the world of online gaming with Taya365 and enjoy top-notch live games. Register today to receive huge rewards and bonuses! Taya365 and enjoy a world of adventure. Whether you're into sports betting, there's something to enjoy. Get started and win big! taya365 app download
Use Taya365 bonuses for maximum victories taya365 app Uncover the world of online gaming with Taya365 and enjoy top-notch live games.
Register today to receive huge rewards and bonuses! Taya365 and enjoy a world of adventure. Whether you're into sports betting, there's something to enjoy. Get started and win big! taya365 app download
دائماً أراهن في 1xbet Sports Betting Egypt – مضمون ومربح! أوصي به الآن! Online betting in Egypt
دائماً أراهن في 1xbet Sports Betting Egypt – مضمون ومربح!
أوصي به الآن! Online betting in Egypt
Mostbet জুয়া – বিশাল প্ল্যাটফর্ম ভার্চুয়াল গেমস জন্য। Mostbet BD
Mostbet জুয়া – বিশাল প্ল্যাটফর্ম ভার্চুয়াল গেমস জন্য। Mostbet BD
Онлайн казино Mostbet – кең ауқымды мүмкіндіктер ұсынады спорттық ставкалар сүйінушілеріне.
mostbet kazakhstan
Онлайн казино Mostbet – кең ауқымды мүмкіндіктер ұсынады спорттық ставкалар сүйінушілеріне. mostbet kazakhstan
На данном сайте всегда доступна актуальная ссылка на мега мориарти, которая обновляется регулярно, чтобы вы могли без проблем попасть на нужную платформу.
На данном сайте всегда доступна актуальная ссылка на мега мориарти, которая обновляется регулярно, чтобы вы могли без проблем попасть на нужную платформу.
why 1xbet is the best online casino site for UAE players Thank you for your openness and openness! �� 400 Bad Request
why 1xbet is the best online casino site for UAE players Thank you for your openness and openness! �� 400 Bad Request
دائماً أراهن في 1xbet مصر – مضمون ومثالي! جربه بنفسك الآن! 1xBet تسجيل
دائماً أراهن في 1xbet مصر – مضمون ومثالي! جربه بنفسك الآن! 1xBet تسجيل
جربت 1xbet Mobile App Egypt – يتميز بواجهة ممتازة، السحب دون مشاكل!
1xBet عروض ترويجية
جربت 1xbet Mobile App Egypt – يتميز بواجهة ممتازة، السحب دون مشاكل!
1xBet عروض ترويجية
هل تحتاج إلى أشهر شركة رهان؟ 1xbet شركة الرهان يقدم أقوى الفرص ودفعات سريعة! Jogar FortuneRabbit sempre foi tão simples.
هل تحتاج إلى أشهر شركة رهان؟ 1xbet شركة الرهان يقدم أقوى الفرص ودفعات سريعة!
Jogar FortuneRabbit sempre foi tão simples.
دائماً أشارك في 1xbet Sports Betting Egypt – مريح ومربح! أنصح به الآن! 1xBet in Egypt
دائماً أشارك في 1xbet Sports Betting Egypt – مريح ومربح! أنصح به الآن! 1xBet in Egypt
هل تبحث عن أقوى كازينو أونلاين؟ 1xbet Egypt يقدم أفضل العروض ودفعات سريعة! 1xBet تطبيق الجوال
هل تبحث عن أقوى كازينو أونلاين؟ 1xbet Egypt يقدم أفضل العروض ودفعات سريعة! 1xBet تطبيق الجوال
دائماً أراهن في 1xbet مصر – مريح ومثالي!
أنصح به الآن! Apostas em futebol
دائماً أراهن في 1xbet مصر – مريح ومثالي! أنصح به الآن! Apostas em futebol