VB.NET 将日期转换为数字 [英] Vb. NET Convert a date to number
问题描述
我在 VB 中有这个代码.网络
I have this code in VB . NET
dim date_e As DateTime
date_e = New DateTime(CLng(Convert.ToDouble("635434240520170000")))
结果是:
12.08.2014 07:07:32
现在我的问题是如何反转该编码以从我自己输入的特定日期和时间获取数字:说吧.
Now my question is how i can reverse that encoding to obtain the number from a specific date and time witch i input myself: Lets' say.
22.09.2014 07:07:32
谢谢!
推荐答案
DateTime
构造函数采用 Long
是自 0001 年 1 月 1 日 00:00:00.000 以来公历中的刻度.
The DateTime
constructor that takes a Long
are the ticks since January 1, 0001 at 00:00:00.000 in the Gregorian calendar.
您只需要先将字符串解析为 Date
,然后您就可以使用它的 Ticks
属性:
You just need to parse the string to Date
first, then you can use it's Ticks
property:
Dim dt = Date.Parse("22.09.2014 07:07:32") ' presumes that this is the correct format
Dim ticks As Long = dt.Ticks
如果输入日期字符串的格式与您当前的文化不同,您可以使用具有正确文化的 Date.Parse
:
If the input date-string is in a different format than your current culture you can use Date.Parse
with the correct culture:
dt = Date.Parse("22.09.2014 07:07:32", New CultureInfo("de-DE"))
或者 - 如果你不知道文化而只知道格式 - Date.ParseExact
:
or - if you don't know the culture but only the format - Date.ParseExact
:
dt = Date.ParseExact("22.09.2014 07:07:32", "dd.MM.yyyy HH:mm:ss", CultureInfo.InvariantCulture)
这篇关于VB.NET 将日期转换为数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!