Python时间并将其转换为C# [英] Python time and converting it to C#

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

问题描述

我几乎已经完成了将一些python代码转换为C#但是随着时间的推移已经阻止了我。我有这两行python:

I am almost done converting some python code into C# but working with time has stopped me. I have these two parts of lines of python:

strftime("%A %d %B %Y %H:%M:%S", gmtime(nextExpected)
strftime("%A %d %B %Y %H:%M:%S", gmtime(s)



我知道第一个是什么bit,它以字符串的格式获取当前时间,但我不理解第二部分,在逗号后面有'gmtime(variable)'。我知道输出应该是将来的一个时间,因为它是什么是输出,但我真的不知道它的作用。有人可以解释一下逗号之后的部分以及它是如何做的吗?第二件事是如何用C#编写的?谢谢


I know what the first bit does, it gets the current time in the format of the string but I do not understand the second part, after the comma where it has 'gmtime(variable)'. I know the output should be a time in the future as that is what is output but I don't really know what it does. Can someone please explain what the part after the comma does and how it does it? The second thing is how would this be written in C#? Thank you

推荐答案

gmtime根据参数中的秒数返回日期/时间。在您的示例中,第一个返回日期/时间作为nextExpected秒,第二个返回s也是秒。秒参数参考纪元值。



要在C#中获取日期,您可以使用:



gmtime returns the a date/time based on the number of seconds in its parameter. In your example, the first one returns a date/time as nextExpected seconds, and the second one s is also seconds. The seconds parameter is referenced to the epoch value.

To get the date in C#, you could use:

DateTime t = new DateTime(nextExpected * TimeSpan.TicksPerSecond);









注意:Python中gmtime中使用的Epoch可能与C#使用的时代。 C#Epoch是公元0001年1月1日,午夜12:00。在Unix中,Epoch是1970年1月1日,在Windows系统上有所不同。要获得Epoch,您可以运行以下Python命令:







Note: The Epoch used in gmtime in Python may be different than the Epoch used by C#. C# Epoch is January 1, 0001 AD, 12:00 Midnight. In Unix the Epoch is January 1, 1970, and is different on Windows systems. To get the Epoch, you can run the following Python command:

gmtime(0)









如果你知道这个时代是什么,你可以这样做:







If you know what the epoch is, you can do this:

DateTime epoch = new DateTime(1970, 1, 1);
DateTime t = epoch.AddSeconds(nextExpected);


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

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