Quote:
Originally posted by Linh
Bash script
now=`date "+%s"`
The above Bash script convert today 's date to a number.
1) Are the year, month, date, hour, minutes, seconds
and thousands of a second involved in this conversion ?
|
No, just seconds. But you can get the
nanoseconds part of the time since the epoch with: date "+%N"
Or in C using the gettimeofday() function.
Quote:
2) What is the mathematical formular for this conversion ?
|
None actually. It's the other way around: The system (kernel) base format for the current time
is in "number of seconds since the epoch". All other time formats are conversions from this.
Quote:
3) What is the C built-in function for the above Bash
script ?
|
That is the time() function. This example below does the same as: date "+%s".
Code:
#include <stdio.h>
#include <time.h>
int main()
{
printf("%ld\n", (long int)time(NULL));
return 0;
}