将DateTime转换为Unixdatetime [英] Convert DateTime to Unixdatetime

查看:65
本文介绍了将DateTime转换为Unixdatetime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以将日期转换为unixdatetime表示形式(自1970年以来数字

秒)。唯一的问题是它只计算整个

天,它忽略了时间部分。所以转换为1/1/1970和1/1/1970 8:00:00 AM

都返回0但是最后应该返回28800.


我的代码:

尝试

Dim dte As DateTime

dte = DateTime.Parse(CmdArgs(1))

Console.WriteLine(DateDiff(DateInterval.Second,

#1/1/1970#,dte))

Catch ex As Exception

控制台.WriteLine(ex.Message)

结束尝试


当我尝试将12:00:00 AM添加到DateDiff funcion vs.net中的日期

删除它。


任何想法?

I have some code to convert a date to the unixdatetime representation (number
of seconds since 1970). Only problem is that it only counts from the whole
day, it ignores the times part. So convert 1/1/1970 and 1/1/1970 8:00:00 AM
both return 0 but the last should return 28800.

My code:
Try
Dim dte As DateTime
dte = DateTime.Parse(CmdArgs(1))
Console.WriteLine(DateDiff(DateInterval.Second,
#1/1/1970#, dte))
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

When I try to add 12:00:00 AM to the date in the DateDiff funcion vs.net
removes that.

Any ideas?

推荐答案

菲尔,


我再次测试了你在上一个问题中向我展示过的方法。


显示28800,显示您显示的值现在。


我希望这会有所帮助,


Cor
Phil,

I tested again the method I showed you in your previous question about that.

It shows 28800 with the values you show now.

I hope this helps,

Cor


" Philip瓦赫纳尔" < pH值************* @ online.nospam> schrieb
"Philip Wagenaar" <ph*************@online.nospam> schrieb
我有一些代码将日期转换为unixdatetime
表示(自1970年以来的秒数)。唯一的问题是,它只计算一整天,它忽略了时代的一部分。所以
转换为1/1/1970和1/1/1970 8:00:00 AM都返回0但是最后
应该返回28800.

我的代码:
尝试
Dim dte As DateTime
dte = DateTime.Parse(CmdArgs(1))


cmdargs(1)包含什么*确切*? br />
Console.WriteLine(DateDiff(DateInterval.Second,#1/1/1970#,dte))
Catch ex As Exception> Console.WriteLine(ex.Message)
结束尝试

当我尝试将12:00:00 AM添加到DateDiff功能的日期时
vs.net删除它。


12:00 AM是午夜。这是* display *是可选的。 #1/1/1970 12:00 AM#和

#1/1/1970#是相同的值。

有什么想法吗?
I have some code to convert a date to the unixdatetime
representation (number of seconds since 1970). Only problem is that
it only counts from the whole day, it ignores the times part. So
convert 1/1/1970 and 1/1/1970 8:00:00 AM both return 0 but the last
should return 28800.

My code:
Try
Dim dte As DateTime
dte = DateTime.Parse(CmdArgs(1))
What *exactly* does cmdargs(1) contain?
Console.WriteLine(DateDiff(DateInterval.Second, #1/1/1970#, dte))
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

When I try to add 12:00:00 AM to the date in the DateDiff funcion
vs.net removes that.
12:00 AM is midnight. It''s *display* is optional. #1/1/1970 12:00 AM# and
#1/1/1970# are identical values.
Any ideas?



使用我前几天给你的解决方案:


dim diff as double


diff = yourdate.subtract(# 1970年1月1日#)。totalseconds

Armin


Use the solution I already gave you some days ago:

dim diff as double

diff = yourdate.subtract(#1/1/1970#).totalseconds
Armin


使用命令行应用程序尝试此操作:

尝试

Dim dte As DateTime

dte = DateTime.Parse(CmdArgs(1))

Console.WriteLine(CType(dte) .Subtract(New

System.DateTime(1970,1,1)),TimeSpan).TotalSeconds.ToString())

Catch ex As Exception

Console.WriteLine(ex.Message)

结束尝试


似乎将命令行参数转换为datetime是错误的。

对此有何看法?


" Cor Ligthert [MVP]"写道:
Cor try this with command line app:
Try
Dim dte As DateTime
dte = DateTime.Parse(CmdArgs(1))
Console.WriteLine(CType(dte.Subtract(New
System.DateTime(1970, 1, 1)), TimeSpan).TotalSeconds.ToString())
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try

Seems that conversion of commandline argument to datetime is going wrong.
Any thoughts on that?

"Cor Ligthert [MVP]" wrote:
菲尔,

我再次测试了你在上一个问题中向我展示的方法。

它显示28800你现在展示的价值观。

我希望这会有所帮助,



这篇关于将DateTime转换为Unixdatetime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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