一段显示所有 DateTimeFormat 属性值的代码,方便察看
C#代码:
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
List
ShowPropertyValue(0, CultureInfo.CurrentCulture.DateTimeFormat);
DateTime dt = DateTime.Now;
richTextBox1.AppendText("/r/n默认日期格式的输出:");
richTextBox1.AppendText(dt.ToString() + "/r/n");
CultureInfo ci = (CultureInfo)CultureInfo.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture = ci;
if (!CultureInfo.CurrentCulture.DateTimeFormat.IsReadOnly)
{
CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern = "yyyy|MM|dd";
CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern = "H+mm+ss";
richTextBox1.AppendText("/r/n自定义日期格式的输出:");
richTextBox1.AppendText(dt.ToString() + "/r/n");
}
}
}
}
窗体文件:
namespace WindowsFormsApplication2
{
partial class Form1
{
///
/// 必需的设计器变量。
///
private System.ComponentModel.IContainer components = null;
///
/// 清理所有正在使用的资源。
///
/// 如果应释放托管资源,为 true;否则为 false。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
///
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Dock = System.Windows.Forms.DockStyle.Top;
this.button1.Location = new System.Drawing.Point(0, 0);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(465, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(0, 23);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(465, 334);
this.richTextBox1.TabIndex = 2;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(465, 357);
this.Controls.Add(this.richTextBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.RichTextBox richTextBox1;
}
}
我的显示结果:
AMDesignator: 上午
Calendar:
MinSupportedDateTime: 0001-01-01 0:00:00
MaxSupportedDateTime: 9999-12-31 23:59:59
AlgorithmType: SolarCalendar
CalendarType: Localized
Eras:
Length: 1
LongLength: 1
Rank: 1
SyncRoot:
IsReadOnly: False
IsFixedSize: True
IsSynchronized: False
TwoDigitYearMax: 2029
IsReadOnly: True
DateSeparator: -
FirstDayOfWeek: Sunday
CalendarWeekRule: FirstDay
FullDateTimePattern: yyyy'年'M'月'd'日' H:mm:ss
LongDatePattern: yyyy'年'M'月'd'日'
LongTimePattern: H:mm:ss
MonthDayPattern: M'月'd'日'
PMDesignator: 下午
RFC1123Pattern: ddd, dd MMM yyyy HH':'mm':'ss 'GMT'
ShortDatePattern: yyyy-MM-dd
ShortTimePattern: H:mm
SortableDateTimePattern: yyyy'-'MM'-'dd'T'HH':'mm':'ss
TimeSeparator: :
UniversalSortableDateTimePattern: yyyy'-'MM'-'dd HH':'mm':'ss'Z'
YearMonthPattern: yyyy'年'M'月'
AbbreviatedDayNames: 日, 一, 二, 三, 四, 五, 六
ShortestDayNames: 日, 一, 二, 三, 四, 五, 六
DayNames: 星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六
AbbreviatedMonthNames: 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月,
MonthNames: 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月,
IsReadOnly: True
NativeCalendarName: 公历
AbbreviatedMonthGenitiveNames: 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月,
MonthGenitiveNames: 一月, 二月, 三月, 四月, 五月, 六月, 七月, 八月, 九月, 十月, 十一月, 十二月,
默认日期格式的输出:2010-02-08 14:37:39
自定义日期格式的输出:2010|02|08 14+37+39