如何:将字符串转换为 DateTime(C# 编程指南)
来源:百度文库 编辑:神马文学网 时间:2024/05/23 15:14:32
如何:将字符串转换为 DateTime(C# 编程指南) http://msdn.microsoft.com/zh-cn/express/cc165448.aspx
更新:2007 年 11 月
通常程序需要支持用户以字符串值的形式输入日期。若要将基于字符串的日期转换为 System..::.DateTime 对象,可以使用 Convert..::.ToDateTime(String) 方法或 DateTime..::.Parse 静态方法,如下面的示例所示。
示例 C# 复制代码// Date strings are interpreted according to the current culture.// If the culture is en-US, this is interpreted as "January 8, 2008",// but if the user's computer is fr-FR, this is interpreted as "August 1, 2008"string date = "01/08/2008";DateTime dt = Convert.ToDateTime(date);Console.WriteLine("Year: {0}, Month: {1}, Day: {2}", dt.Year, dt.Month, dt.Day);// Specify exactly how to interpret the string.IFormatProvider culture = new System.Globalization.CultureInfo("fr-FR", true);// Alternate choice: If the string has been input by an end user, you might // want to format it according to the current culture:// IFormatProvider culture = System.Threading.Thread.CurrentThread.CurrentCulture;DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);Console.WriteLine("Year: {0}, Month: {1}, Day {2}", dt2.Year, dt2.Month, dt2.Day);/* Output (assuming first culture is en-US and second is fr-FR):Year: 2008, Month: 1, Day: 8Year: 2008, Month: 8, Day 1*/
如何:将字符串转换为 DateTime(C# 编程指南)
创建文件或文件夹(C# 编程指南)
如何将Excel数据表格转换为图片格式(转)
字符串转换为数值的库函数
如何将一个字符串加密
探讨C#中字符串的加密-Asp.net|网络编程语言|学习网
vc 浮点数转换为内存十六进制字符串
如何将CString转换为char[] VC/MFC / 基础类
如何将word中的项目编号转换为普通文本_AirPlay
如何将磁盘从FAT格式转换为NTFS格式
如何将PDF文件转换为TXT文件!
如何将PDF文件转换为TXT文件(转载
Sql Server datetime 常用日期格式转换
C#中Split分隔字符串的应用(C#、split、分隔、字符串)
C#高级编程(第2版)
C#网络编程初探(1)
字符串的转换
Loadrunner脚本编程(4)-数据类型操作和字符串操作
将十六进制数转换为十进制如何来转换呢比如一十六进制数4EBC67转换为十进制是516003...
C#网络编程概述
2009年8月编程语言榜:.NET前景如何?[1] - visual c# 编程语言 ba...
如何将word文档、pdf文件相互转换(全)
把十六进制字符串转换为数字的几个C语言版本 - Graphics的专栏
字符串和字符数组转换