使用模式将字符串转换为日期时间 [英] Convert a string to a datetime using a pattern

查看:60
本文介绍了使用模式将字符串转换为日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个代表日期的字符串如下:dd-.MM-.yyyy hh:mm。

我怎么能把这个字符串转换为DateTime类型(我更喜欢以某种方式将

设置为一个模式,如果有可能的话因为我有其他

的可能性为dd~MM ~yyyy,hh:mm")?


谢谢。

解决方案

string myString =" 1-1-2000" ;;

DateTime myDateTime = DateTime.Parse(myString);


希望这有帮助,

Arjen


" Iwan Petrow" < XX **** @ abv.bg> schreef in bericht

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...



我有一个代表日期的字符串如下:dd-.MM-.yyyy hh:mm。
如何将此字符串转换为DateTime类型(我更喜欢以某种方式将其设置为模式,如果有可能,因为我有其他可能性为dd~MM~yyyy,hh:mm)?

谢谢。



" Iwan Petrow" < XX **** @ abv.bg>在消息中写道

新闻:11 ********************** @ o13g2000cwo.googlegr oups.com ...

我有一个表示日期的字符串如下:dd-.MM-.yyyy hh:mm。
如何将此字符串转换为DateTime类型(我更喜欢某种方式)如果可能的话,将其设置为模式,因为我有其他的可能性,如dd~MM~yyyy,hh:mm)?




DateTime.Parse(...)


谢谢。


但我希望文化不变。


我找到了一个类DateTimeFormatInfo这个已经足够好但是我想要

来禁止AM和PM。我使用HH但它不起作用(它接受它们)。


任何禁止它们的想法(上午和下午)?


Hi,

I have a string which represent a date as follow: "dd-.MM-.yyyy hh:mm".
How could I convert this string to DateTime type (I prefer somehow to
set this as a pattern if it is possible because I have other
possibilities as "dd~MM~yyyy, hh:mm")?

Thanks.

解决方案

string myString = "1-1-2000";
DateTime myDateTime = DateTime.Parse(myString);

Hope this helps,
Arjen

"Iwan Petrow" <xx****@abv.bg> schreef in bericht
news:11**********************@o13g2000cwo.googlegr oups.com...

Hi,

I have a string which represent a date as follow: "dd-.MM-.yyyy hh:mm".
How could I convert this string to DateTime type (I prefer somehow to
set this as a pattern if it is possible because I have other
possibilities as "dd~MM~yyyy, hh:mm")?

Thanks.



"Iwan Petrow" <xx****@abv.bg> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

I have a string which represent a date as follow: "dd-.MM-.yyyy hh:mm".
How could I convert this string to DateTime type (I prefer somehow to
set this as a pattern if it is possible because I have other
possibilities as "dd~MM~yyyy, hh:mm")?



DateTime.Parse(...)


Thanks.

But I want culture invariant.

I''ve found a class DateTimeFormatInfo which is good enough but I want
to forbid AM and PM. I use HH but it doesn''t work (it accepts them).

Any ideas for forbidding them (AM and PM)?


这篇关于使用模式将字符串转换为日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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