Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create timestamp in seconds

I have this task to populate this field:

x_fp_timestamp is the timestamp created when the form is generated. It is equal to the number of seconds since January 1, 1970 in UTC (Coordinated Universal Time).

So what I do in C# is

 long ts =  DateTime.Now.Ticks / TimeSpan.TicksPerSecond;

But in that case I am getting this error:

  • x_fp_timestamp : x_fp_timestamp invalid. Not within 15 minutes of present time: Thu Jan 10 21:30:25 GMT 2013. Expected 1357853425 plus/minus 900, but received 63493442997.

So my question is how to generate current timestamp in seconds?

like image 789
Friend Avatar asked Jan 10 '13 21:01

Friend


People also ask

How do you find the timestamp in seconds?

To get the current date/time in seconds, use getTime()/1000.

How do you calculate a timestamp?

If you'd like to calculate the difference between the timestamps in seconds, multiply the decimal difference in days by the number of seconds in a day, which equals 24 * 60 * 60 = 86400 , or the product of the number of hours in a day, the number of minutes in an hour, and the number of seconds in a minute.

How do you convert timestamps to hours?

Converting hours # There are 60 seconds in a minute, and 60 minutes in an hour. We'll divide our timestamp by 60 , and then by 60 again.

How do you create a timestamp in JavaScript?

How to Use valueOf() to Generate Timestamps in JS. Just like the getTime() method, we have to attach the valueOf() method to a new Date() object in order to generate a Unix timestamp. The new Date() object, without getTime() or valueOf() , returns the information about your current time.


1 Answers

DateTime.Now.Ticks does not start at 1970; try something like this instead:

 (DateTime.Now.ToUniversalTime() - new DateTime (1970, 1, 1)).TotalSeconds
like image 162
praseodym Avatar answered Oct 21 '22 02:10

praseodym