1

the title might be a bit confusing but I had no plan how to name it. I am programming an emulator for a game and the game is using Timestamp for the premium time calculation.

What I need is a function to get the current timestamp and then a function that adds x days to it, so for example:

int daysToAdd = 10;
long Timestamp_normal = GetTimestamp();
long newTimestamp = AddDays(Timestamp_normal, daysToAdd);

Kind Regards

2 Answers2

0

You can use DateTime to do the calculations and convert that to a timestamp:

var startDate = DateTime.Now;
long startTimeStamp = startDate.ToTimeStamp();

var endDate = startDate.AddDays(1);
long endTimeStamp = endDate.ToTimeStamp();

There are various way to make a "timestamp" from a DateTime (depending on your definition of timestamp), so pick any that works and move that to a DateTime extension method as demonstrated above:

public static class DateTimeExtensions
{
    public static long ToTimeStamp(this DateTime input)
    {
        // your implementation here
    }
}

For implementations see Function that creates a timestamp in c#, How to convert datetime to timestamp using C#/.NET (ignoring current timezone), How to get the unix timestamp in C#, and so on.

Community
  • 1
  • 1
CodeCaster
  • 139,522
  • 20
  • 204
  • 252
0

Probably you just wanted to get the Ticks for that particular day

long ts1 = DateTime.Now.AddDays(10).Ticks;
Rahul
  • 73,987
  • 13
  • 62
  • 116
  • The question is not _"How to make a timestamp from a DateTime"_, and that question has been answered plenty of times before (see three links in my answer). – CodeCaster Jul 19 '15 at 10:30
  • @CodeCaster, didn't the question says *a function to get the current timestamp and then a function that adds x days to it*? I didn't see a need for a specific function though. – Rahul Jul 19 '15 at 10:32