Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 将字符串转换为日期时间格式_Vb.net_Datetime Format - Fatal编程技术网

Vb.net 将字符串转换为日期时间格式

Vb.net 将字符串转换为日期时间格式,vb.net,datetime-format,Vb.net,Datetime Format,我从一个无法更改的数据源中获取日期和时间,我需要将其转换为DateTime 字符串的格式如下所示 timestamp="20131204T171054+0000" 使用DateTime.Parse函数。必须传递字符串值作为其参数。然后,您可以为其结果指定日期时间。这会将字符串转换为指示日期时间的值。下面是将示例字符串转换为datatime的示例。我对你在问题中给出的字串一无所知 Dim value As String = "2000-02-02" Dim time As DateTim

我从一个无法更改的数据源中获取日期和时间,我需要将其转换为
DateTime

字符串的格式如下所示

timestamp="20131204T171054+0000"

使用
DateTime.Parse
函数。必须传递字符串值作为其参数。然后,您可以为其结果指定日期时间。这会将字符串转换为指示日期时间的值。下面是将示例字符串转换为datatime的示例。我对你在问题中给出的字串一无所知

  Dim value As String = "2000-02-02"
  Dim time As DateTime = DateTime.Parse(value)
您可以使用并指定一个

您的示例看起来“yyyymmddthhmmsk”可能有效

在vb.net中

Dim timestamp As String = "20131204T171054+0000"
Dim dt As DateTime = DateTime.ParseExact(timestamp, "yyyyMMddTHHmmssK", CultureInfo.InvariantCulture)
在C#


如果您要处理定义良好的环境,我会采用Haji的方法。全局时间处理是一个难题

我将字符串拆分为有效的日期和时间:

Dim dt As DateTime = "2013.12.04 17:10:54"

然后调整偏移量。

我不得不求助于使用子字符串这是我的代码:

Dim Date As Date = datestamp.Substring(6, 2) & "/" & datestamp.Substring(4, 2) & "/" & datestamp.Substring(0, 4) & " " &
                            timestamp.Substring(0, 2) & ":" & timestamp.Substring(2, 2) & ":" & timestamp.Substring(4, 2)

这与OP提到的特定日期时间格式有什么关系?@YuriyGalanter抱歉我的错误。根据问题标题,我为示例转换提供了一些字符串。
Dim Date As Date = datestamp.Substring(6, 2) & "/" & datestamp.Substring(4, 2) & "/" & datestamp.Substring(0, 4) & " " &
                            timestamp.Substring(0, 2) & ":" & timestamp.Substring(2, 2) & ":" & timestamp.Substring(4, 2)