如何在.NET中获取此DateTime格式 [英] How can I get this DateTime format in .NET

查看:46
本文介绍了如何在.NET中获取此DateTime格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将一些DateTime格式化为 W3C DateTime格式:-

I'm trying to format some DateTime into this W3C DateTime format :-

Complete date plus hours and minutes:
eg. YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)

where:
 YYYY = four-digit year
 MM   = two-digit month (01=January, etc.)
 DD   = two-digit day of month (01 through 31)
 hh   = two digits of hour (00 through 23) (am/pm NOT allowed)
 mm   = two digits of minute (00 through 59)
 ss   = two digits of second (00 through 59)
 s    = one or more digits representing a decimal fraction of a second
 TZD  = time zone designator (Z or +hh:mm or -hh:mm)

我原来有这个...

var myDateTime = someDateTime.ToString("s",
    System.Globalization.CultureInfo.InvariantCulture);

但这会导致一个字符串:

But that results in a string of :

2011-08-31T08:46:00

任何人都可以帮忙吗?

推荐答案

使用以下内容:

yourDateTime.ToString( "yyyy-MM-ddTHH:mmK", CultureInfo.InvariantCulture );

在DateTime格式上,这比您想了解的还要多:

Here is more than you'll ever want to know on DateTime formats:

http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

这篇关于如何在.NET中获取此DateTime格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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