Function that creates a timestamp in c#

前端 未结 6 506
小蘑菇
小蘑菇 2020-11-30 19:25

I was wondering, is there a way to create a timestamp in c# from a datetime? I need a millisecond precision value that also works in Compact Framework(saying that since Date

6条回答
  •  眼角桃花
    2020-11-30 19:50

    I always use something like the following:

    public static String GetTimestamp(this DateTime value)
    {
        return value.ToString("yyyyMMddHHmmssfff");
    }
    

    This will give you a string like 200905211035131468, as the string goes from highest order bits of the timestamp to lowest order simple string sorting in your SQL queries can be used to order by date if you're sticking values in a database

提交回复
热议问题