开发者

VB.net ISo DateFormat

I have a date in VB.net that is stored in ISO 8601 format

'Date here is local time in germany   
Dim s As String = "2010-09-27T16:54:28+02:00"

Dim dt As DateTime
If Date.TryParse(s, dt) = True Then

End If

When I use try to parse it shows me date in my local timezone,

how can I get date as

开发者_运维技巧2010-9-27 4:54 PM as well as GMT DATE ?


A date is not stored internally with any specific representation.

You need to format it for display, using the correct DateTime format string (either custom or standard):

Dim s As String = "2010-09-27T16:54:28+02:00"

Dim dt As DateTime
If Date.TryParse(s, dt) = True Then
    Dim gmt as String = dt.ToUniversalTime().ToString("r", CultureInfo.InvariantCulture)
    Dim custom as String = dt.ToUniversalTime().ToString("yyyy-M-d h:mm tt", CultureInfo.InvariantCulture)
End If
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜