如何在c#中将字符串日期转换为datetime [英] How to convert string date to datetime in c#

查看:84
本文介绍了如何在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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