DateTime.ToString() Patterns

DateTime.ToString() Patterns

All the patterns:

0 MM/dd/yyyy 08/22/2006
1 dddd, dd MMMM yyyy Tuesday, 22 August 2006
2 dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2006 06:30
3 dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2006 06:30 AM
4 dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2006 6:30
5 dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2006 6:30 AM
6 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
7 MM/dd/yyyy HH:mm 08/22/2006 06:30
8 MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
9 MM/dd/yyyy H:mm 08/22/2006 6:30
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
10 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM
11 MM/dd/yyyy HH:mm:ss 08/22/2006 06:30:07
12 MMMM dd August 22
13 MMMM dd August 22
14 yyyy‘-‘MM‘-‘dd‘T‘HH‘:‘mm‘:‘ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
15 yyyy‘-‘MM‘-‘dd‘T‘HH‘:‘mm‘:‘ss.fffffffK 2006-08-22T06:30:07.7199222-04:00
16 ddd, dd MMM yyyy HH‘:‘mm‘:‘ss ‘GMT‘ Tue, 22 Aug 2006 06:30:07 GMT
17 ddd, dd MMM yyyy HH‘:‘mm‘:‘ss ‘GMT‘ Tue, 22 Aug 2006 06:30:07 GMT
18 yyyy‘-‘MM‘-‘dd‘T‘HH‘:‘mm‘:‘ss 2006-08-22T06:30:07
19 HH:mm 06:30
20 hh:mm tt 06:30 AM
21 H:mm 6:30
22 h:mm tt 6:30 AM
23 HH:mm:ss 06:30:07
24 yyyy‘-‘MM‘-‘dd HH‘:‘mm‘:‘ss‘Z‘ 2006-08-22 06:30:07Z
25 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07
26 yyyy MMMM 2006 August
27 yyyy MMMM 2006 August

The patterns for DateTime.ToString ( ‘d‘ ) :

0 MM/dd/yyyy 08/22/2006

The patterns for DateTime.ToString ( ‘D‘ ) :

0 dddd, dd MMMM yyyy Tuesday, 22 August 2006

The patterns for DateTime.ToString ( ‘f‘ ) :

0 dddd, dd MMMM yyyy HH:mm Tuesday, 22 August 2006 06:30
1 dddd, dd MMMM yyyy hh:mm tt Tuesday, 22 August 2006 06:30 AM
2 dddd, dd MMMM yyyy H:mm Tuesday, 22 August 2006 6:30
3 dddd, dd MMMM yyyy h:mm tt Tuesday, 22 August 2006 6:30 AM

The patterns for DateTime.ToString ( ‘F‘ ) :

0 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( ‘g‘ ) :

0 MM/dd/yyyy HH:mm 08/22/2006 06:30
1 MM/dd/yyyy hh:mm tt 08/22/2006 06:30 AM
2 MM/dd/yyyy H:mm 08/22/2006 6:30
3 MM/dd/yyyy h:mm tt 08/22/2006 6:30 AM

The patterns for DateTime.ToString ( ‘G‘ ) :

0 MM/dd/yyyy HH:mm:ss 08/22/2006 06:30:07

The patterns for DateTime.ToString ( ‘m‘ ) :

0 MMMM dd August 22

The patterns for DateTime.ToString ( ‘r‘ ) :

0 ddd, dd MMM yyyy HH‘:‘mm‘:‘ss ‘GMT‘ Tue, 22 Aug 2006 06:30:07 GMT

The patterns for DateTime.ToString ( ‘s‘ ) :

0 yyyy‘-‘MM‘-‘dd‘T‘HH‘:‘mm‘:‘ss 2006-08-22T06:30:07

The patterns for DateTime.ToString ( ‘u‘ ) :

0 yyyy‘-‘MM‘-‘dd HH‘:‘mm‘:‘ss‘Z‘ 2006-08-22 06:30:07Z

The patterns for DateTime.ToString ( ‘U‘ ) :

0 dddd, dd MMMM yyyy HH:mm:ss Tuesday, 22 August 2006 06:30:07

The patterns for DateTime.ToString ( ‘y‘ ) :

0 yyyy MMMM 2006 August

Building a custom DateTime.ToString Patterns

The following details the meaning of each pattern character. Note the K and z character.

d Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero
dd Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero
ddd Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc)
dddd Represents the full name of the day of the week (Monday, Tuesday etc)
h 12-hour clock hour (e.g. 7)
hh 12-hour clock, with a leading 0 (e.g. 07)
H 24-hour clock hour (e.g. 19)
HH 24-hour clock hour, with a leading 0 (e.g. 19)
m Minutes
mm Minutes with a leading zero
M Month number
MM Month number with leading zero
MMM Abbreviated Month Name (e.g. Dec)
MMMM Full month name (e.g. December)
s Seconds
ss Seconds with leading zero
t Abbreviated AM / PM (e.g. A or P)
tt AM / PM (e.g. AM or PM
y Year, no leading zero (e.g. 2001 would be 1)
yy Year, leadin zero (e.g. 2001 would be 01)
yyy Year, (e.g. 2001 would be 2001)
yyyy Year, (e.g. 2001 would be 2001)
K Represents the time zone information of a date and time value (e.g. +05:00)
z With DateTime values, represents the signed offset of the local operating system‘s time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6)
zz As z but with leadin zero (e.g. +06)
zzz With DateTime values, represents the signed offset of the local operating system‘s time zone from UTC, measured in hours and minutes. (e.g. +06:00)
f Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value.
ff Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value.
fff Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value.
ffff Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock‘s resolution is approximately 10-15 milliseconds.
fffff Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock‘s resolution is approximately 10-15 milliseconds.
ffffff Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock‘s resolution is approximately 10-15 milliseconds.
fffffff Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock‘s resolution is approximately 10-15 milliseconds.
F Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero.
: Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds.
/ Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days.
" Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\).
Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (‘) characters.
%c Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers.

||\c || Represents the escape character, and displays the character "c" as a literal when that character is preceded by the escape character (\). To insert the backslash character itself in the result string, the application should use two escape characters ("\\").

Any other character copies any other character to the result string, without affecting formatting. ||

原文地址:https://www.cnblogs.com/yuanshou/p/10660591.html

时间: 2024-08-13 03:49:05

DateTime.ToString() Patterns的相关文章

实例365(6)---------DateTime.ToString格式化日期,使用DateDiff方法获取日期时间的间隔数

一:DateTime.ToString格式化日期,截图 二:代码 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace TmrFormat { public part

用DateTime.ToString(string format)输出不同格式的日期

Copy自:http://www.cnblogs.com/xvqm00/archive/2009/02/19/1394093.html DateTime.ToString()函数有四个重载.一般用得多的就是不带参数的那个了.殊不知,DateTime.ToString(string format)功能更强大,能输出不同格式的日期.以下把一些情况罗列出来,供大家参考.有些在MSDN上有的就没有列出来了. 1.         y代表年份,注意是小写的y,大写的Y并不代表年份. 2.         

DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决:

原文:DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决: DateTime.ToString("dd/MM/yyyy");后,不能直接Convert.ToDateTime的解决: DateTime.ParseExact(this.DateBegin.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.GetCultureIn

如何表示各个时区的时间DateTime.ToString()

使用sqlite进行时间的插入的时候,使用了 DateTime.ToString("s")  //s: 2008-06-15T21:15:07 插入到数据库之后,发现时间被加了8个小时 找了半天资料,才找到原因 This profile defines two ways of handling time zone offsets: 有两种方式处理时区的时差 Times are expressed in UTC (Coordinated Universal Time), with a s

C#DateTime.ToString 格式化时间字符串和数值类型转换为字符串

我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34,如果要换成200606,06-2006,2006-6-6或更多的格式该怎么办呢?这里将要用到:DateTime.ToString的方法. 一.DateTime.ToString格式模式 下面列出了DateTime.ToString(string format) 中 format 参数.这些模式是区分大小写的:例如,识别"MM",但不识别"mm". d         

C# DateTime.ToString()的各种日期格式

DateTime.ToString()的各种日期格式 例: ToString:2016/9/27 0:00:00 ToString("yyyy/MM/dd"):2016/09/27 ToString("yyyy-MM-dd"):2016-09-27 ToString("yyyy.MM.dd"):2016.09.27 ToString("dd/MM/yyyy"):27/09/2016 ToString("dd-MM-y

【转载ToString()转换格式;DateTime.ToString()用法详解】

ToString()转换格式;DateTime.ToString()用法详解 格式模式 说明和关联属性 c.C 货币格式.关联的属性包括: CurrencyDecimalDigits, CurrencyDecimalSeparator, CurrencyGroupSeparator, CurrencyGroupSizes, CurrencyNegativePattern, CurrencyPositivePattern, CurrencySymbol. d.D 十进制格式. e.E 科学计数(指

转,DateTime.ToString()格式详解

DateTime.ToString()用法详解 我们经常会遇到对时间进行转换,达到不同的显示效果,默认格式为:2006-6-6 14:33:34 如果要换成成200606,06-2006,2006-6-6或更多的格式该怎么办呢?这里将要用到:DateTime.ToString的方法(String, IFormatProvider)示例:using System;using System.Globalization;String format="D";DateTime date=Data

c# DateTime.ToString()转换为统一的格式

DateTime.ToString()的转换结果时根据当前电脑的显示格式来转换的,不能同意,而且有些格式我们想将他们重新转换为时间时,会报错,如: 2017/11/21/周二 10:23:57,如果转换这个字符串为DateTime时,会失败,所以就需要给程序设置一个默认的转换方式,每次在调用DateTime.ToString()的时候就直接转换为我们想要的格式,如下: DateTime.ToString("yyyy-MM-dd HH:mm:ss") 但是这种方法有时觉得太麻烦,每个都需