如何将毫秒转换为C#中的日期格式? [英] How to convert Milliseconds to date format in C#?

查看:1397
本文介绍了如何将毫秒转换为C#中的日期格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中如何将Unix风格的时间戳转换为yyyy-MM-ddThh:mm:ssZ?

解决方案

开始通过将您的毫秒转换为 TimeSpan

  var time = TimeSpan。 FromMilliseconds(毫秒); 

现在,在.NET 4中,您可以调用 .ToString()具有格式字符串参数。请参阅 http://msdn.microsoft.com/en-us/ library / system.timespan.tostring.aspx



在以前的.NET版本中,您必须从TimeSpan的属性手动构造格式化的字符串。


In C# how can I convert Unix-style timestamp to yyyy-MM-ddThh:mm:ssZ?

解决方案

Start by converting your milliseconds to a TimeSpan:

var time = TimeSpan.FromMilliseconds(milliseconds);

Now, in .NET 4 you can call .ToString() with a format string argument. See http://msdn.microsoft.com/en-us/library/system.timespan.tostring.aspx

In previous versions of .NET, you'll have to manually construct the formatted string from the TimeSpan's properties.

这篇关于如何将毫秒转换为C#中的日期格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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