日期和时间的转换
来源:互联网 发布:免费刷cf点软件 编辑:程序博客网 时间:2024/04/30 20:57
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
The Format method takes the following form, where XXX is the name of the numeric base data-type:
virtual XXX Format(String* format,IServiceObjectProvider* sp)
Similar to the Format methods found in other .NET Framework data types, the DateTime Format method takes a string format character and an IServiceObjectProvider object. The IServiceObjectProvider object specifies the culture. The method defaults to the current culture if null (in Visual Basic Nothing) is passed.
The following table shows the valid format strings.
Format character Description Default return format
d Short date pattern MM/dd/yyyy
D Long date pattern dddd, MMMM dd, yyyy
f Full (long date + short time) dddd, MMMM dd, yyyy HH:mm
F Full date time pattern (long date + long time) dddd, MMMM dd, yyyy HH:mm:ss
g General (short date + short time) MM/dd/yyyy HH:mm
G General (short date + long time) MM/dd/yyyy HH:mm:ss
m,M Month day pattern MMMM dd
r,R RFC1123 pattern ddd, dd MMM yyyy HH':'mm':'ss'GMT'
s Sortable date time pattern: conforms to ISO 8601 yyyy-MM-dd HH:mm:ss
t Short time pattern HH:mm
T Long time pattern HH:mm:ss
u Similar to "s"but uses universal time instead of local time. yyyy-MM-dd HH:mm:ss
U Universal sortable date time pattern dddd, MMMM dd, yyyy HH:mm:ss
Y,y Year month pattern MMMM, yyyy
Given a DateTime object, MyDate, representing 12:01 AM Sunday, January 1, 2000, the following example illustrates some of the formatting options available:
[C#]
MyDate.Format( "d", null );
// returns the string "01/01/2000"
MyDate.Format( "D", null );
// returns the string "Sunday, January 1, 2000"
MyDate.Format( "f", null );
// returns the string "Sunday January 1, 2000 12:01 AM"
The ToString Method will quickly convert a DateTime type value into a string. Similar to other .NET Framework base types, it requires no arguments and is easy to use. Unlike the Format method, the ToString method is unaffected by the current culture and only takes one form. The following example converts a DateTime value into a string value:
[C#]
DateTime MyDate = new DateTime(2000, 01, 01)
MyDate.ToString();
//returns "01/01/2000 00:00:00"
<
日期和时间的转换';return true">
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
The DateTime data type also contains a Format method and a ToString method that return a string-formatted representation of the original value. The Format method can be used to format a value in one of fifteen common ways, while the ToString method can only be used to format a value in one way.The Format method takes the following form, where XXX is the name of the numeric base data-type:
virtual XXX Format(String* format,IServiceObjectProvider* sp)
Similar to the Format methods found in other .NET Framework data types, the DateTime Format method takes a string format character and an IServiceObjectProvider object. The IServiceObjectProvider object specifies the culture. The method defaults to the current culture if null (in Visual Basic Nothing) is passed.
The following table shows the valid format strings.
Format character Description Default return format
d Short date pattern MM/dd/yyyy
D Long date pattern dddd, MMMM dd, yyyy
f Full (long date + short time) dddd, MMMM dd, yyyy HH:mm
F Full date time pattern (long date + long time) dddd, MMMM dd, yyyy HH:mm:ss
g General (short date + short time) MM/dd/yyyy HH:mm
G General (short date + long time) MM/dd/yyyy HH:mm:ss
m,M Month day pattern MMMM dd
r,R RFC1123 pattern ddd, dd MMM yyyy HH':'mm':'ss'GMT'
s Sortable date time pattern: conforms to ISO 8601 yyyy-MM-dd HH:mm:ss
t Short time pattern HH:mm
T Long time pattern HH:mm:ss
u Similar to "s"but uses universal time instead of local time. yyyy-MM-dd HH:mm:ss
U Universal sortable date time pattern dddd, MMMM dd, yyyy HH:mm:ss
Y,y Year month pattern MMMM, yyyy
Given a DateTime object, MyDate, representing 12:01 AM Sunday, January 1, 2000, the following example illustrates some of the formatting options available:
[C#]
MyDate.Format( "d", null );
// returns the string "01/01/2000"
MyDate.Format( "D", null );
// returns the string "Sunday, January 1, 2000"
MyDate.Format( "f", null );
// returns the string "Sunday January 1, 2000 12:01 AM"
The ToString Method will quickly convert a DateTime type value into a string. Similar to other .NET Framework base types, it requires no arguments and is easy to use. Unlike the Format method, the ToString method is unaffected by the current culture and only takes one form. The following example converts a DateTime value into a string value:
[C#]
DateTime MyDate = new DateTime(2000, 01, 01)
MyDate.ToString();
//returns "01/01/2000 00:00:00"
<
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 728x15, 创建于 08-4-23MSDN */google_ad_slot = "3624277373";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
<script type="text/javascript"><!--google_ad_client = "pub-2947489232296736";/* 160x600, 创建于 08-4-23MSDN */google_ad_slot = "4367022601";google_ad_width = 160;google_ad_height = 600;//--></script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
- 日期和时间的转换
- 日期和时间的转换
- python转换时间戳和日期时间格式的转换
- 时间戳和日期的互相转换
- 时间戳和日期的转换
- js日期和时间戳的转换
- 日期时间的转换
- 时间日期的转换
- SAP内时间戳和日期时间的转换
- mysql中的时间戳和日期时间的转换
- 转换日期和时间(sql)
- Sybase日期和时间转换
- 时间戳和日期转换
- 日期和时间戳转换
- 时间戳和日期转换
- java和数据库之间的日期和时间转换
- java和数据库之间的日期和时间转换
- java和数据库之间的日期和时间转换
- 一个用php3编写的简单计数器
- Numeric Parse Method
- 网站当前的在线人数
- 数值变换时的格式化字符举例
- 最简单的PHP程序--记数器
- 日期和时间的转换
- BBS(php & mysql)完整版(一)
- 用C#创建COM对象
- 建立动态的WML站点(三)
- C# 2.0 Specification(迭代器)(一)
- 用文本文件制作留言板提示(下)
- c#中分割字符串的几种方法
- 建立动态的WML站点(二)
- C# 2.0 Specification(迭代器)(二)