显示日期时间为MM / DD / YYYY HH:mm格式C# [英] Display datetime into MM/dd/yyyy HH:mm format c#
问题描述
在数据库中的日期时间被存储在MM-DD-YYYY HH:MM:SS fromat
。
不过,我想以显示日期时间MM / DD / YYYY HH:MM格式。
我用的String.Format()尝试了。
In database datetime is being stored in MM-dd-yyyy HH:mm:ss fromat.
However, I want to display datetime in "MM/dd/yyyy HH:mm" format.
I tried it by using String.Format().
txtCampaignStartDate.Text = String.Format("{0:MM/dd/yyyy
HH:mm}",appCampaignModel.CampaignStartDateTime);
下面 appCampaignModel.CampaignStartDateTime
是具有价值的DateTime对象的MM-DD-YYYY HH:MM格式
Here appCampaignModel.CampaignStartDateTime
is DateTime object having value in "MM-dd-yyyy HH:mm" format.
我要显示的MM / DD / YYYY HH:MM。格式
谁能帮我这个?
推荐答案
在此格式的斜线 MM / DD / YYYY HH:MM
的意思是:与取代我当前区域性的实际分隔符。你必须使用 CultureInfo.InvariantCulture
明确地
The slashes in this format MM/dd/yyyy HH:mm
mean: "replace me with the actual separator of the current culture". You have to use CultureInfo.InvariantCulture
explicitely:
txtCampaignStartDate.Text = appCampaignModel.CampaignStartDateTime.ToString("MM/dd/yyyy HH:mm", CultureInfo.InvariantCulture);
在数据库中的日期时间被存储在MM-DD-YYYY HH:MM:SS fromat
In database datetime is being stored in MM-dd-yyyy HH:mm:ss fromat.
不要日期时间
存储与格式,这意味着您将它们保存为(N)VARCHAR
。使用日期时间
代替。
Don't store datetimes
with a format which means that you store them as (n)varchar
. Use datetime
instead.
这篇关于显示日期时间为MM / DD / YYYY HH:mm格式C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!