我怎样才能使用“datetime”方法? [英] How can I use "datetime" method?

查看:93
本文介绍了我怎样才能使用“datetime”方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示我拍摄日期的屏幕。例如我写的17/12/2014,屏幕显示2014年12月17日

解决方案

如果DateTime对象有效;没有错误将其解析为DateTime,然后使用.ToString方法将此日期时间对象转换为您选择的字符串表示形式。对你来说这样可行。



 dateTime.ToString( < span class =code-string> dd MMMM yyyy);  //  日期月份和年份 





使用上面的代码在接口中以字符串格式写入dateTime。有关更多信息,请参阅此文档 [ ^ ]。


使用DateTime.TryParse:

  public   void  ShowLongDate( string  inputDate)
{
DateTime date;
if (!DateTime.TryParse(inputDate, out date))
{
Console.WriteLine( 无效日期: + inputDate);
}
else
{
Console.WriteLine(date.ToString( D));
}
}


下面是解决方案链接:



http://msdn.microsoft.com/en-us/library/ 8kb3ddd4(v = vs.110).aspx [ ^ ]


How can show screen that I take date. For example I write17/12/2014 ,screen show me 17 december 2014

解决方案

If the DateTime object is valid; no error parsing it to DateTime, then use the .ToString method to convert this date time object to a string representation of your choice. For you this would work.

dateTime.ToString("dd MMMM yyyy"); // date month and year



Use above code to write the dateTime in string format in the interface. For more please read this document[^].


Use DateTime.TryParse:

public void ShowLongDate(string inputDate)
   {
   DateTime date;
   if (!DateTime.TryParse(inputDate, out date))
       {
       Console.WriteLine("Invalid date: " + inputDate);
       }
   else
       {
       Console.WriteLine(date.ToString("D"));
       }
   }


here is the solution link below:

http://msdn.microsoft.com/en-us/library/8kb3ddd4(v=vs.110).aspx[^]


这篇关于我怎样才能使用“datetime”方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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