如何删除“。”在上午,我只是想要,点导致异常 [英] How to remove "." in a.m. ,i just want am, dot causes to exception

查看:97
本文介绍了如何删除“。”在上午,我只是想要,点导致异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我将系统时区设置为西班牙语,



我正在获得当前的时间as:17/02/2016 02:31:09 am



因为有。在a.m中,我在插入记录时从sql数据库端获得异常。那么我怎么能把这个时间转换成只是



我必须在C#端或SQL数据库查询端转换它。



我必须将此值作为日期时间传递。



我尝试过:



我尝试过System.DateTime.ParseExact(....)方法,但它没有给我解决方案。

解决方案

正如我昨天向你解释的那样:不要这样做。

从字符串转换日期和/或时间时转换失败。 [ ^ ]

所有这一切都将发生在你身上将出现下一个错误。

在C#代码中转换它,并将其作为DateTime参数值传递给SQL。







通过以下链接: https://msdn.microsoft.com/en-us/library/5hh873ya(v = VS.90)的.aspx [ ^ ]





Quote:

您可以从CultureInfo DateTimeFormat属性检索格式字符串,该属性是DateTimeFormatInfo实例。这反过来又有像ShortDatePattern和ShortTimePattern这样的属性,包含格式字符串:



CultureInfo us = new CultureInfo(en-US);

string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern;

string shortUsTimeFormatString = us.DateTimeFormat.ShortTimePattern;



CultureInfo uk = new CultureInfo( en-GB);

string shortUkDateFormatString = uk.DateTimeFormat.ShortDatePattern;

string shortUkTimeFormatString = uk.DateTimeFormat.ShortTimePattern;

If你只想使用CultureInfo格式化日期/时间,使用ToString方法将DateTime转换为字符串时将其作为IFormatter传递:



string us = myDate.ToString(new CultureInfo(en-US));

string uk = myDate.ToString(new CultureInfo(en-GB));





ref: c# - 如何根据文化信息获取日期和时间格式? - 堆栈溢出 [ ^ ]


  string  dateAsString =   17/02/2016 02:31:09 am; 
DateTime dt = DateTime.ParseExact(dateAsString.Replace( 。m m), dd / MM / yyyy hh:mm:ss tt,System.Globalization.CultureInfo.CurrentCulture);


Hi,

I set my system timezone to spanish,

I am getting currentdate time as: 17/02/2016 02:31:09 a.m.

due to having "." in a.m ,I am getting exception from sql database side while inserting a record. So how can I convert this time a.m to just am

I have to convert this on either C# side or SQL database query side.

I have to pass this value as a datetime varaible only.

What I have tried:

I have tried with System.DateTime.ParseExact(....) method, but it didn't give me the solution.

解决方案

As I explained to you yesterday: don't do that.
Conversion failed when converting date and/or time from character string.[^]
All that will happen is you will get the next error coming up.
Convert it in your C# code, and pass it as a DateTime parameter value to SQL.


Hi,


Go through this link : https://msdn.microsoft.com/en-us/library/5hh873ya(v=vs.90).aspx[^]


Quote:

You can retrieve the format strings from the CultureInfo DateTimeFormat property, which is a DateTimeFormatInfo instance. This in turn has properties like ShortDatePattern and ShortTimePattern, containing the format strings:

CultureInfo us = new CultureInfo("en-US");
string shortUsDateFormatString = us.DateTimeFormat.ShortDatePattern;
string shortUsTimeFormatString = us.DateTimeFormat.ShortTimePattern;

CultureInfo uk = new CultureInfo("en-GB");
string shortUkDateFormatString = uk.DateTimeFormat.ShortDatePattern;
string shortUkTimeFormatString = uk.DateTimeFormat.ShortTimePattern;
If you simply want to format the date/time using the CultureInfo, pass it in as your IFormatter when converting the DateTime to a string, using the ToString method:

string us = myDate.ToString(new CultureInfo("en-US"));
string uk = myDate.ToString(new CultureInfo("en-GB"));



ref : c# - How can I get date and time formats based on Culture Info? - Stack Overflow[^]


string dateAsString = "17/02/2016 02:31:09 a.m";
DateTime dt = DateTime.ParseExact(dateAsString.Replace(".m", "m"), "dd/MM/yyyy hh:mm:ss tt", System.Globalization.CultureInfo.CurrentCulture);


这篇关于如何删除“。”在上午,我只是想要,点导致异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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