简体   繁体   中英

C# Unix timestamp

What I want to do is block a user from doing something for 24 hours after they have reached a limit. I have coded the limit part, I just need to know how to block it if it hasn't been 24 hours.

Here is an example on how I want to do it. Update the user's account using a query and set the timestamp (Unix) to that time. Then I don't know how I can get another timestamp of the time they try to do it and check if the new timestamp is 24 hours between the last?

I have medium experience with C# but timestamps is one section I know nothing about with c#. Ss there anyone here that can help or provide a good tutorial? Or an idea on how I can learn more about it. I'm looking for the best way to do this. If Unix timestamps aren't it then please let me know and provide me with a better way if you can.

//Example
if (!CODE_HERE_FOR_NOT_24_HOURS)
{
    MessageBox.Show("You have reached your limit for today. Try again tomorow");
    return; 
}
else
{
    //Code here
}

In C#, you'd typically use DateTime.UtcNow , and use a DateTime , not a unix timestamp.

You can always check to see if its been less than 24 hours via:

if (timeStamp > DateTime.UtcNow.AddDays(-1))
{
   // It's been less than 24 hours
}

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