当前位置:网站首页>C.Net timestamp and time conversion support time zone
C.Net timestamp and time conversion support time zone
2022-07-26 23:07:00 【Application Hunter】
/// <summary>
/// This time zone date time to timestamp
/// </summary>
/// <param name="datetime"> Time </param>
/// <param name="toMilliseconds"> Is it accurate to milliseconds </param>
/// <returns></returns>
public static long ToUnixTimeStamp(this DateTime datetime, bool toMilliseconds = true)
{
DateTime beginTimeUtc = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);// Standard time
DateTime timeUTC = datetime.ToUniversalTime();// Turn it into time
TimeSpan ts = (timeUTC - beginTimeUtc);// Subtract the standard start time from the current standard time
if (toMilliseconds)
{
return (Int64)ts.TotalMilliseconds;// Accurate to milliseconds
}
return (Int64)ts.TotalSeconds;// Accurate to seconds
}
/// <summary>
/// Time stamp to local time zone date time
/// </summary>
/// <param name="TimeStamp"></param>
/// <param name="toMilliseconds"> Is it accurate to milliseconds </param>
/// <returns></returns>
public static DateTime ToDateTime( this long TimeStamp, bool toMilliseconds = true)
{
DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);// Standard time
if (toMilliseconds)
{
return startTime.AddTicks(TimeStamp * 10000).ToLocalTime();// Standard time to local time
}
else
{
return startTime.AddTicks(TimeStamp * 10000000).ToLocalTime();// Standard time to local time
}
}
边栏推荐
- Ribbon load balancing
- Domestic DRAM will be mass produced by the end of the year, but the road ahead is still long!
- Monte Carlo search tree (UCT) based on confidence upper bound to realize four sub chess
- 摩尔定律的新推力,英特尔先进封装技术详解!
- Practical project: boost search engine
- [hcip] OSPF relationship establishment
- 【HCIP】OSPF 特殊区域、汇总、认证
- Huawei atlas900 reveals the secret: it integrates thousands of shengteng 910 chips, and its computing power is comparable to 500000 PCs!
- [hcip] OSPF special area, summary, certification
- 企业如何缓解物联网和工业物联网安全风险
猜你喜欢

Shardingsphere JDBC keyword problem

SQL Basics

7.27 watch first | openeuler is ambitious, open source Huizhi creates the future - the most detailed agenda of the Euler sub forum of the open atom global open source summit is released

Hcia-r & s self use notes (23) DHCP

数据库全栈工程师(DevDBOps)低首付、高回报,先就业后付款

Hcia-r & s self use notes (20) VLAN comprehensive experiment, GVRP

Eureka basic use

Regular expressions and bypass case recurrence

STM32 how to use serial port

Is test development development development?
随机推荐
Luo Xu talks with Siemens wanghaibin: advanced manufacturing requires benefits from Digitalization
SQL Basics
Esmfold: a new breakthrough in protein structure prediction after alphafold2
基于C语言的页式文件系统
[hcip] OSPF special area, summary, certification
Interview: your most impressive bug, for example
2019 biometric forum successfully ended: these ten highlights should not be missed!
Page file system based on C language
Why did kylin 990 series fail to meet cortex-a77 and Mali G77?
商汤科技CEO徐立:公司估值已超70亿美元,不急于上市
Programmer growth chapter 29: how to motivate employees?
Will the approval in advance affect the formal approval?
基本的SELECT语句
【无标题】
Kt6368a Bluetooth chip development precautions and problem collection - long term update
【HCIP】OSPF 路由计算
沟通中经常用到的几个库存术语
Shardingsphere JDBC keyword problem
After working for one year, I have some insights (written in 2017)
gateway基本使用