VB.net ISO 日期格式 [英] VB.net ISo DateFormat

查看:32
本文介绍了VB.net ISO 日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VB.net 中有一个以 ISO 8601 格式存储的日期

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

当我使用 try 解析时,它会在我的本地时区显示日期,

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

我怎样才能获得日期

2010-9-27 4:54 PM 以及 GMT 日期?

2010-9-27 4:54 PM as well as GMT DATE ?

推荐答案

日期不会以任何特定表示形式存储在内部.

A date is not stored internally with any specific representation.

您需要使用正确的 DateTime 格式字符串(自定义标准):

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

这篇关于VB.net ISO 日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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