如何在c#中将字符串日期转换为datetime

编程入门 行业动态 更新时间:2024-10-11 21:24:50
本文介绍了如何在c#中将字符串日期转换为datetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将字符串日期转换为日期时间c# 例如: string s; s =june / 2014; 这个如何转换日期时间 datetime frmmonth; 我的o / p来这样 frmmonth = 2014年6月 任何一个没有请回答我谢谢。

Hi, how to convert string date to datetime in c# for example : string s; s= "june/2014"; this one how to convert datetime datetime frmmonth; my o/p come like this frmmonth= june/2014 any one no please answer me thank you.

推荐答案

string s; s ="June/2014"; Console.WriteLine("frmmonth="Convert.ToDateTime(s).ToString("MMMM/yyyy")); . This would help you out. You can also get the date by the following way. string s; s ="10/June/2014"; Console.WriteLine("frmmonth="Convert.ToDateTime(s).ToString("dd/MMMM/yyyy"));

[Agent_Spock] - 添加代码括号

[Agent_Spock] - Added Code Brackets

check DateTime.ParseExact Method [ ^ ] check DateTime.ParseExact Method[^] DateTime frmmonth =DateTime.ParseExact(s,"MMMM/yyyy", CultureInfo.InvariantCulture);

你的字符串中没有日期请参考下面的链接,这可能对你有帮助。 此链接可以帮助您 或者如果你想转换为dd / mm / yyyy你可以采取任何默认日期,因为你需要自己的功能要在字符串中添加硬编码的固定日期,请尝试转换日期格式 you don't have date in your string please refer the link below this might help you. this link can help you or you can take any date default if you want to convert in dd/mm/yyyy, for that you need to make your own function to add the hardcoded fixed date in your string then try to convert in date format

更多推荐

如何在c#中将字符串日期转换为datetime

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

发布评论

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

>www.elefans.com

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