简体   繁体   English

自定义长日期格式-C#

[英]Custom Long Date Format - C#

I have a drop down menu containing several different dates, where one will be selected based in if it matches a date in an Excel sheet I'm using. 我有一个包含几个不同日期的下拉菜单,其中一个日期与我使用的Excel工作表中的日期匹配时,将在其中选择一个日期。 The dates in the dropdown menu are of the format Wednesday, August 9, 2016 . 下拉菜单中的日期格式为Wednesday, August 9, 2016

Now my plan was to convert the Excel data to a long date format and compare the two; 现在,我的计划是将Excel数据转换为长日期格式,然后将两者进行比较。 however, I noticed that C#'s long date format includes a zero preceding the day, like Wednesday, August 09, 2016 . 但是,我注意到C#的长日期格式在一天前包括零,例如Wednesday, August 09, 2016日, Wednesday, August 09, 2016

Is there a way that I can remove that extra 0 in front of the 9 when converting to a long date format in C#? 当用C#转换为长日期格式时,是否可以删除9前面的多余0? Or is there another method I should try. 还是我应该尝试另一种方法。

如果您的格式是固定的,则可以使用自定义格式字符串

date.ToString("dddd, MMMM d, yyyy", CultureInfo.GetCultureInfo("en-us"));

应该这样做:

mydate.ToString("dddd, MMMM d, yyyy", CultureInfo.CreateSpecificCulture("en-US"));

this format can do the job: 这种格式可以胜任:

String date = DateTime.Now.ToString("dddd,MMMM,d,yyyy",CultureInfo.GetCultureInfo("en-us"));
   // Wednesday, August 9, 2016

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM