csharp datetime to timestamp

Code Example - csharp datetime to timestamp

                
                        DateTimeOffset.UtcNow.ToUnixTimeSeconds()
                    
                
 

csharp convert Unix time in seconds to datetime

                        
                                public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}
                            
                        
 

convert timestamp to datetime csharp code

                        
                                public static DateTime UnixTimeStampToDateTime( double unixTimeStamp )
{
    // Unix timestamp is seconds past epoch
    System.DateTime dtDateTime = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    dtDateTime = dtDateTime.AddSeconds( unixTimeStamp ).ToLocalTime();
    return dtDateTime;
}
                            
                        
 

csharp datetime now timestamp

                        
                                var Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                            
                        
 

csharp timestamp now

                        
                                DateTime now = DateTime.Now;
        Console.WriteLine("NOW: " + now);
                            
                        
 

csharp timestamp

                        
                                public static String GetTimestamp(DateTime value)
{
    return value.ToString("yyyyMMddHHmmssffff");
}
//  ...later on in the code
String timeStamp = GetTimestamp(new DateTime());
Console.WriteLine(timeStamp);
                            
                        
 

csharp convert timestamp to datetime

                        
                                DateTime authTimeUtc = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(filteredAuthUserClaims.AuthTimestamp)).DateTime;
                            
                        
 

csharp convert datetime to timespan

                        
                                Add .TimeofDay to the datetime value to make it of type TimeSpan

DateTime.TimeOfDay