国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

標準 DateTime 格式字符串

2024-07-21 02:23:32
字體:
來源:轉載
供稿:網友
標準 datetime 格式字符串包含下表中的一個格式說明符字符。如果下表中沒有該格式說明符,將引發運行時異常。如果格式字符串在長度上比單個字符長(即使多出的字符是空白),則格式字符串被解釋為自定義格式字符串。

請注意,這些格式說明符產生的輸出字符串受“區域選項”控制面板中的設置的影響。計算機的區域性設置或日期和時間設置不同,將生成不同的輸出字符串。

格式字符串顯示的時間和日期分隔符由與當前區域性的 datetimeformat 屬性關聯的 dateseparator 和 timeseparator 字符定義。然而,如果 invariantculture 被“r”、“s”和“u”說明符引用,與 dateseparator 和 timeseparator 字符關聯的字符不隨當前區域性更改。

下表描述了用來格式化 datetime 對象的標準格式說明符。

格式說明符 名稱 說明
d 短日期模式 顯示由與當前線程關聯的 datetimeformatinfo.shortdatepattern 屬性定義的模式或者由指定格式提供程序定義的模式。
d 長日期模式 顯示由與當前線程關聯的 datetimeformatinfo.longdatepattern 屬性定義的模式或者由指定格式提供程序定義的模式。
t 短時間模式 顯示由與當前線程關聯的 datetimeformatinfo.shorttimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。
t 長時間模式 顯示由與當前線程關聯的 datetimeformatinfo.longtimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。
f 完整日期/時間模式(短時間) 顯示長日期和短時間模式的組合,由空格分隔。
f 完整日期/時間模式(長時間) 顯示由與當前線程關聯的 datetimeformatinfo.fulldatetimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。
g 常規日期/時間模式(短時間) 顯示短日期和短時間模式的組合,由空格分隔。
g 常規日期/時間模式(長時間) 顯示短日期和長時間模式的組合,由空格分隔。
m 或 m 月日模式 顯示由與當前線程關聯的 datetimeformatinfo.monthdaypattern 屬性定義的模式或者由指定格式提供程序定義的模式。
r 或 r rfc1123 模式 顯示由與當前線程關聯的 datetimeformatinfo.rfc1123pattern 屬性定義的模式或者由指定格式提供程序定義的模式。這是定義的標準,并且屬性是只讀的;因此,無論所使用的區域性或所提供的格式提供程序是什么,它總是相同的。屬性引用 cultureinfo.invariantculture 屬性并遵照自定義模式“ddd, dd mmm yyyy hh:mm:ss g/mt”。請注意,“gmt”中的“m”需要轉義符,因此它不被解釋。格式化并不修改 datetime 的值,所以您必須在格式化之前將值調整為 gmt。
s 可排序的日期/時間模式;符合 iso 8601 顯示由與當前線程關聯的 datetimeformatinfo.sortabledatetimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。屬性引用 cultureinfo.invariantculture 屬性,格式遵照自定義模式“yyyy-mm-ddthh:mm:ss”。
u 通用的可排序日期/時間模式 顯示由與當前線程關聯的 datetimeformatinfo.universalsortabledatetimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。因為它是定義的標準,并且屬性是只讀的,因此無論區域性或格式提供程序是什么,模式總是相同的。格式化遵照自定義模式“yyyy-mm-dd hh:mm:ssz”。格式化日期和時間時不進行時區轉換;所以,請在使用格式說明符之前將本地日期和時間轉換為通用時間。
u 通用的可排序日期/時間模式 顯示由與當前線程關聯的 datetimeformatinfo.fulldatetimepattern 屬性定義的模式或者由指定格式提供程序定義的模式。請注意,顯示的時間是通用時間,而不是本地時間。
y 或 y 年月模式 顯示由與當前線程關聯的 datetimeformatinfo.yearmonthpattern 屬性定義的模式或者由指定格式提供程序定義的模式。
任何其他單個字符 未知說明符

下面的示例說明了標準格式字符串如何與 datetime 對象一起使用。

[visual basic]
dim dt as datetime = datetime.now
dim dfi as datetimeformatinfo = new datetimeformatinfo()
dim ci as cultureinfo = new cultureinfo("de-de")

' make up a new custom datetime pattern, for demonstration.
dfi.monthdaypattern = "mm-mmmm, ddd-dddd"

' use the datetimeformat from the culture associated
' with the current thread.

console.writeline( dt.tostring("d") )
console.writeline( dt.tostring("m") )

' use the datetimeformat from the specific culture passed.
console.writeline( dt.tostring("d", ci ) )

' use the settings from the datetimeformatinfo object passed.
console.writeline( dt.tostring("m", dfi ) )

' reset the current thread to a different culture.
thread.currentthread.currentculture = new cultureinfo("fr-be")
console.writeline( dt.tostring("d") )

[c#]
datetime dt = datetime.now;
datetimeformatinfo dfi = new datetimeformatinfo();
cultureinfo ci = new cultureinfo("de-de");

// make up a new custom datetime pattern, for demonstration.
dfi.monthdaypattern = "mm-mmmm, ddd-dddd";

// use the datetimeformat from the culture associated
// with the current thread.
console.writeline( dt.tostring("d") );
console.writeline( dt.tostring("m") );

// use the datetimeformat from the specific culture passed.
console.writeline( dt.tostring("d", ci ) );

// use the settings from the datetimeformatinfo object passed.
console.writeline( dt.tostring("m", dfi ) );

// reset the current thread to a different culture.
thread.currentthread.currentculture = new cultureinfo("fr-be");
console.writeline( dt.tostring("d") );

請參見
格式化概述 | 格式化類型 | 日期與時間格式字符串 | 標準 datetime 格式字符串輸出示例

發送有關此主題的意見

© 2001-2002 microsoft corporation。保留所有權利。



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 苍南县| 南溪县| 拉萨市| 阿鲁科尔沁旗| 南乐县| 敦煌市| 全州县| 金阳县| 凤台县| 合作市| 连云港市| 吴川市| 三亚市| 长武县| 渭南市| 九龙城区| 濉溪县| 尉犁县| 红原县| 莱州市| 堆龙德庆县| 门头沟区| 黑山县| 紫阳县| 琼海市| 高雄县| 阿拉善右旗| 任丘市| 耒阳市| 林周县| 四川省| 丽江市| 精河县| 元阳县| 涿鹿县| 屯昌县| 潞西市| 奉贤区| 武城县| 贺兰县| 永清县|