gpt4 book ai didi

c# - 日期时间格式 yyyymm

转载 作者:行者123 更新时间:2023-11-30 18:52:48 30 4
gpt4 key购买 nike

除了我需要的那个:yyyymm 之外,我已经找到了您能想到的所有 DateTime 格式。我该如何获得它?

我正在使用以下代码:

List <string> routines = new List<string>();
routines.Add("1 - Routine");
routines.Add("6 - Planned Outage");

int year = 2011;
int quarter = 1;

DateTime timeframe = new DateTime(year, (quarter * 3), 01).AddMonths(1);

var results =

(from wo in WORKORDERs

join wot in WORKORDERTYPEs on wo.Wot_oi equals wot.Wotyoi

join pri in PRIORITies on wo.Prio_oi equals pri.Priooi

join s in SITEs on wo.BEparn_oi equals s.Siteoi

where wo.Audt_created_dttm.Value.Year >= year - 3 && wo.Audt_created_dttm.Value.Year >= 2006
&& wo.Audt_created_dttm < timeframe && (s.Id =="NM" || s.Id == "TH") &&
!wot.Id.Contains("stand") && !(wo.Ci_cnc_date != null && pri.Prioid != "1 - Routine" &&
pri.Prioid != "6 - Planned Outage") && (SqlMethods.Like(pri.Prioid, "1%") ||
SqlMethods.Like(pri.Prioid, "2%") || SqlMethods.Like(pri.Prioid, "3%"))

select new {PM = wo.Wosource, Site = s.Id, Priority = pri.Prioid, Worktype = wot.Id,
WoNumber = wo.Id, Description = wo.Aenm, CreateDate = wo.Audt_created_dttm,
CloseDate = wo.Clsdt_date,
MonthNum = String.Format("{0:yyyy mm}", wo.Clsdt_date),
Planning = routines.Contains(pri.Prioid) ? "Planned" : "Unplanned"});

我尝试使用:

MonthNum = String.Format("{0:yyyy mm}",  wo.Clsdt_date) 

这给了我正确的年份,但月份都是 00。我猜这是因为 wo.Clsdt_date 的格式与我的字符串格式不同(它是 mm/dd/yyyy)。

有什么想法吗?

最佳答案

您需要MM,而不是mmmm 是分钟。

关于c# - 日期时间格式 yyyymm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10852017/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com