覆盖字符串DateTime

编程入门 行业动态 更新时间:2024-10-24 14:15:10
本文介绍了覆盖字符串DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的朋友, 我需要帮助来解决此问题.我正在尝试将字符串[4/20/2011 8:17:21 AM]转换为DateTime.为此,我尝试了以下方法:.

Dear Friend, i need a help to solve this problem.I am trying to convert a string [4/20/2011 8:17:21 AM] to DateTime. For this i tried like the following ways..

string date = "4/20/2011 8:17"; Convert.ToDateTime(date); and DateTime.ParseExact(date,"M/dd/yyy",System.Globalization.CultureInfo.CurrentCulture);

但是我收到错误消息字符串未被识别为有效的DateTime." 请帮助我..

But i am getting error message "String was not recognized as a valid DateTime." Please help me ..

推荐答案

对于Convert.ToDateTime调用,可以(或应该).对于ParseExact调用,您的格式字符串必须为: "M/dd/yyyy h:mm" For the Convert.ToDateTime call, it''s okay (or should be). For the ParseExact call, your format string needs to be this: "M/dd/yyyy h:mm"

尝试一下, try this, string strDateTime = "2/28/1992 12:15:12"; DateTime myDateTime = DateTime.Parse(strDateTime ); Or myDate = DateTime.ParseExact("2009-05-08 14:40:52,531", "yyyy-MM-dd HH:mm:ss,fff",System.Globalization.CultureInfo.InvariantCulture)

尝试使用System.Globalization try with this using System.Globalization CultureInfo provider = CultureInfo.InvariantCulture; string date = "04/20/2011 08:17"; DateTime dt1 = DateTime.ParseExact(date, "g",provider);

更多推荐

覆盖字符串DateTime

本文发布于:2023-08-01 08:53:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267014.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   DateTime

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!