你可以在C#中如何将日期时间格式化为特定的非标准格式?

huangapple go评论58阅读模式
英文:

How can I format a date time to a specific, non-standard format in c#

问题

我需要以下输出字符串:

星期三 2023年6月14日 16:21 UTC
英文:

In c#, how could I format a date/time to get the specific output format?

DateTime dt = DateTime.UtcNow(); 
//Assuming the current UTC date/time is 6/14/2023 16:21 UTC

I need the following output string:

Wednesday 14. June 2023 16:21 UTC

答案1

得分: 2

DateTime dt = DateTime.UtcNow();
string formattedDateTime = dt.ToString("dddd dd. MMMM yyyy HH:mm UTC");
Console.WriteLine(formattedDateTime);

英文:
DateTime dt = DateTime.UtcNow(); 
string formattedDateTime = dt.ToString("dddd dd. MMMM yyyy HH:mm UTC");
Console.WriteLine(formattedDateTime);

huangapple
  • 本文由 发表于 2023年6月15日 01:15:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76476059.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定