DateTime's representation in milliseconds?

后端 未结 7 961
遥遥无期
遥遥无期 2020-11-30 05:21

I have a SQL-server timestamp that I need to convert into a representation of time in milliseconds since 1970. Can I do this with plain SQL? If not, I\'ve extracted it into

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 06:04

    This other solution for covert datetime to unixtimestampmillis C#.

    private static readonly DateTime UnixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    
    public static long GetCurrentUnixTimestampMillis()
    {
        DateTime localDateTime, univDateTime;
        localDateTime = DateTime.Now;          
        univDateTime = localDateTime.ToUniversalTime();
        return (long)(univDateTime - UnixEpoch).TotalMilliseconds;
    } 
    

提交回复
热议问题