using System;
sealed class Greet {
static void Main(string[] args) {
string nowString
= DateTime.Now.ToString("yyyy年MM月dd日 dddd tt hh时mm分");
Console.WriteLine(nowString);
}
}
// 2008年01月04日 星期五 下午 08时11分
格式参数可以参考MSDN: .NET Framework Developer''s Guide - Standard Date and Time Format Strings
引用MSDN上的简明表格如下:(http://msdn2.microsoft.com/en- us/library/system.globalization.datetimeformatinfo.aspx
标准格式:
引用
Format pattern
Associated Property/Description
d
ShortDatePattern
D
LongDatePattern
f
Full date and time (long date and short time)
F
FullDateTimePattern (long date and long time)
g
General (short date and short time)
G
General (short date and long time)
m, M
MonthDayPattern
o, O
Round-trip date/time pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
r, R
RFC1123Pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture
s
SortableDateTimePattern (based on ISO 8601) using local time; with this format pattern, the formatting or parsing operation always uses the invariant culture
t
ShortTimePattern
T
LongTimePattern
u
UniversalSortableDateTimePattern using the format for universal time display; with this format pattern, the formatting or parsing operation always uses the invariant culture
U
Full date and time (long date and long time) using universal time
y, Y
YearMonthPattern
Java中一些获取当前日期的方法(4)
时间:2011-10-07 javaeye RednaxelaFX
自定义格式:
引用
Format pattern
Description
d, %d
The day of the month. Single-digit days do not have a leading zero. The application specifies "%d" if the format pattern is not combined with other format patterns.
dd
The day of the month. Single-digit days have a leading zero.
ddd
The abbreviated name of the day of the week, as defined in AbbreviatedDayNames.
dddd
The full name of the day of the week, as defined in DayNames.
f, %f
The fraction of a second in single-digit precision. The remaining digits are truncated. The application specifies "%f" if the format pattern is not combined with other format patterns.
ff
The fraction of a second in double-digit precision. The remaining digits are truncated.
fff
The fraction of a second in three-digit precision. The remaining digits are truncated.
ffff
The fraction of a second in four-digit precision. The remaining digits are truncated.
fffff
The fraction of a second in five-digit precision. The remaining digits are truncated.
ffffff
The fraction of a second in six-digit precision. The remaining digits are truncated.
fffffff
The fraction of a second in seven-digit precision. The remaining digits are truncated.
F, %F
Displays the most significant digit of the seconds fraction. Nothing is displayed if the digit is zero. The application specifies "%F" if the format pattern is not combined with other format patterns.
FF
Displays the two most significant digits of the se
|