简体   繁体   中英

C# How to get specific current time

var myReader = cmd.ExecuteReader();
if (myReader.HasRows)
{
    myReader.Read();
    var expiryDate = myReader.GetDateTime("expirationdate");
    if (DateTime.Now > expiryDate)
}

This is the code i'm using for getting current time but its getting time of the computer so if someone else try to use this which lives in another time there is a chance him to get fail. how i get UTC+2 time (i live in turkey and i want turkeys current time)

If you don't want to worry about time zone then use UtcNow instead of Now . Of course that means that your database data must be in UTC as well. Hopefully all of your data was stored based on a single time zone, in which case the conversion is straightforward (just add a constant time to each value).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM