特殊字符串转换成时间

yinxubest87 2009-12-30 02:44:07
字符串格式示例: Oct 27 13:00:01 2009

这种字符串时间格式转化成时间 有没有特定的函数,怎么转?
...全文
421 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kensouterry 2009-12-30
  • 打赏
  • 举报
回复
自己写函数对字符串进行解析呀!
antony1029 2009-12-30
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 hdngo 的回复:]
SnippetCompiler真方便,哈哈哈哈哈~

C# codeusing System;using System.Collections.Generic;using System.Globalization;publicclass MyClass
{publicstaticvoid RunSnippet()
{
DateTimeFormatInfo dtfi= DateTimeFormatInfo.InvariantInfo;string _time="Oct 27 13:00:01 2009";
DateTime dt= DateTime.ParseExact(_time,"MMM dd HH:mm:ss yyyy", dtfi);
WL(dt.ToString());
RL();
}#region Helper methodspublicstaticvoid Main()
{try
{
RunSnippet();
}catch (Exception e)
{string error=string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
Console.WriteLine(error);
}finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}privatestaticvoid WL(object text,paramsobject[] args)
{
Console.WriteLine(text.ToString(), args);
}privatestaticvoid RL()
{
Console.ReadLine();
}privatestaticvoid Break()
{
System.Diagnostics.Debugger.Break();
}#endregion
}
[/Quote]
SnippetCompiler真方便,的确不错啊。呵呵!!!
cailee 2009-12-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 hdngo 的回复:]
C# codeusing System.Globalization;

DateTimeFormatInfo dtfi= DateTimeFormatInfo.InvariantInfo;string _time="Oct 27 13:00:01 2009";
DateTime dt= DateTime.ParseExact(_time,"MMM dd HH:mm:ss yyyy", dtfi);?-
[/Quote]
顶。
zhujiazhi 2009-12-30
  • 打赏
  • 举报
回复
CultureInfo myCIintl = new CultureInfo( "es-ES", false );
string xx = DateTime.Now.ToString("dd MMM yyyy", myCIintl);
hhc123 2009-12-30
  • 打赏
  • 举报
回复

DateTime date1 = new DateTime(2008, 4, 10, 6, 30, 0);
Console.WriteLine(date1.ToString("MMM dd HH:mm:ss yyyy",
CultureInfo.CreateSpecificCulture("en-US")));
HDNGO 2009-12-30
  • 打赏
  • 举报
回复
SnippetCompiler真方便,哈哈哈哈哈~

using System;
using System.Collections.Generic;
using System.Globalization;

public class MyClass
{
public static void RunSnippet()
{
DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
string _time = "Oct 27 13:00:01 2009";
DateTime dt = DateTime.ParseExact(_time, "MMM dd HH:mm:ss yyyy", dtfi);
WL(dt.ToString());
RL();
}

#region Helper methods

public static void Main()
{
try
{
RunSnippet();
}
catch (Exception e)
{
string error = string.Format("---\nThe following error occurred while executing the snippet:\n{0}\n---", e.ToString());
Console.WriteLine(error);
}
finally
{
Console.Write("Press any key to continue...");
Console.ReadKey();
}
}

private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}

private static void RL()
{
Console.ReadLine();
}

private static void Break()
{
System.Diagnostics.Debugger.Break();
}

#endregion
}
hhc123 2009-12-30
  • 打赏
  • 举报
回复
DateTime date1 = new DateTime(2008, 4, 10);
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("en-US")));
// Displays Thursday, April 10, 2008
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("pt-BR")));
// Displays quinta-feira, 10 de abril de 2008
Console.WriteLine(date1.ToString("D",
CultureInfo.CreateSpecificCulture("es-MX")));
// Displays jueves, 10 de abril de 2008
HDNGO 2009-12-30
  • 打赏
  • 举报
回复
using System.Globalization;

DateTimeFormatInfo dtfi = DateTimeFormatInfo.InvariantInfo;
string _time = "Oct 27 13:00:01 2009";
DateTime dt = DateTime.ParseExact(_time, "MMM dd HH:mm:ss yyyy", dtfi);
Console.WriteLine(dt.ToString());
yinxubest87 2009-12-30
  • 打赏
  • 举报
回复
如果可以的话,代入上面的时间试下,我转过,但有上面那时间 特殊,呵呵!
yinxubest87 2009-12-30
  • 打赏
  • 举报
回复
可以在C# 里格式化,也可以在数据库里 SQL
wefgod 2009-12-30
  • 打赏
  • 举报
回复
DateTime.Parse,你找找···
wefgod 2009-12-30
  • 打赏
  • 举报
回复
你找看看DateTime有没有相关的函数
好像没有直接处理字符串的
但是你这个···可以分解吧···
等高人的回答
平生我自如 2009-12-30
  • 打赏
  • 举报
回复
这样的倒是可以:to_date(char,'yyyy-……')[Quote=引用 1 楼 biny101 的回复:]
没有吧,好像只有2009-12-27 13:00:01这样才行吧
[/Quote]
biny101 2009-12-30
  • 打赏
  • 举报
回复
没有吧,好像只有2009-12-27 13:00:01这样才行吧

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧