如何解析Datetime SQL [英] How to parse Datetime SQL

查看:74
本文介绍了如何解析Datetime SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c#中解析SQL日期时间。



在数据库中就像这样2003-12-31 00:00:00

i想这样12/31/2003 12:00:00 AM



请帮忙...

解决方案

数据库中的日期不会以任何格式存储,除非它们存储为字符串 - 您说您没有这样做。相反,它们从任意时间点开始存储为几微秒。



当你将它们转换为字符串进行演示时,它们只获取一种格式 - 这将是通常可以在演示软件而不是SQL中完成,以便它采用用户首选的格式。

但您可以在SQL中选择字符串的格式:w3Schools [ ^ ]


http://www.dotnetperls.com/ datetime-sql [ ^ ]


string date =2003-12-31 00:00:00;

string [] Arr = Convert.ToDateTime(date).GetDateTimeFormats();

Console.WriteLine(Arr [71]);

Console.ReadLine ();

How to parse SQL datetime in c#.

in Database its like this "2003-12-31 00:00:00"
i want like this "12/31/2003 12:00:00 AM"

please help...

解决方案

Dates in a database aren't stored with any format, unless they are stored as strings - which you say you aren't doing. Instead, they are stored as a number of microseconds since an arbitrary point in time.

They only acquire a format when you convert them to a string for presentation - which would normally be done in presentation software rather than in SQL so that it is in the format preferred by the user.
But you can select the format for the string in SQL:w3Schools[^]


http://www.dotnetperls.com/datetime-sql[^]


string date = "2003-12-31 00:00:00";
string [] Arr=Convert.ToDateTime(date).GetDateTimeFormats();
Console.WriteLine(Arr[71]);
Console.ReadLine();


这篇关于如何解析Datetime SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆