如何手动更改日期格式? [英] how to change the date format manually ?

查看:79
本文介绍了如何手动更改日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我需要手动更改文本框中给定输入的日期格式。

输入值将为格式化为dd-mm-yyyy - 字符串,输出应显示为dd / mm / yyyy-String。



谢谢。

Hi,

I need to change the date format manually for a given input from a text box.
The input value will be formatted as a dd-mm-yyyy - String, and the output shall be displayed as dd/mm/yyyy-String.

Thank you.

推荐答案

试试这个: -



try this:-

string strFormatDt = Convert.ToDateTime(txtDt.Text).ToString("dd/MM/yyyy");


[MarcoB]

这个解决方案表现不佳,因为对于dateTime .Year,dateTime.Month和dateTime.Day是一个方法和一个属性获取操作调用。

[/ MarcoB]



看看这个:

[MarcoB]
This solution will perform badly, since for dateTime.Year, dateTime.Month and dateTime.Day is a method and a property get operation called.
[/MarcoB]

look at this:
private  string ConvertDatetimeToValid(DateTime dateTime)
       {
           string datetime = string.Concat(dateTime.Day.ToString(), "/", dateTime.Month.ToString(), "/", dateTime.Year.ToString());
 
           return datetime;
       }






浏览此页面 [ ^ ]我发现以下解决方案可以帮助您:



Hi,

after browsing this page[^] I found the following solution which helps you:




DateTime dt = DateTime.Now;
String.Format("{0:MM/dd/yyyy}", dt);          // "03/09/2008"





这篇关于如何手动更改日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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