[C / c ++] [Linux] type of operations Summary notes
The timestamp is 2020/03/25 11:09:42 .761197, where .761197 is microseconds.
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int main()
{
char time[100] = "2020/03/25 11:09:42 .761197";
char time_format[100] = "%Y/%m/%d %H:%M:%S";
printf("origin is %s\n", time);
/* to tm */
struct tm tm;
strptime(time, time_format, &tm);
printf("tm is %04d-%02d-%02d %02d:%02d:%02d\n", 1900 + tm.tm_year, 1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
/* to time_t */
time_t tt;
tt = mktime(&tm);
printf("time_t is %lu\n", tt);
/* to timeval */
struct timeval tv;
tv.tv_sec = tt;
tv.tv_usec = atoi(time + 21); // 21 = strlen("2020/03/25 11:09:42 .")
printf("timeval is %ld.%06ld\n", tv.tv_sec, tv.tv_usec);
return 0;
}
origin is 2020/03/25 11:09:42 .761197
tm is 2020-03-25 11:09:42
time_t is 1585105782
timeval is 1585105782.761197
Original address: http://www.cnblogs.com/codemo/archive/2012/05/18/2507251.html Author:Code example Source: The copyright belongs to the copyright belong to the blog, welcome to reprint, but thi...
1, the conversion of string to time_t The time_t here can pass an unsigned int type parameter, which means the number of seconds that 1970.1.1 0:0:0 starts counting, and returns the string structure s...
time_t tm timeval time string and conversion methods 1, the conventional storage time 1) time_t type, this is essentially a long integer representing the number of seconds from 1970-01-01 00:00:00 to ...
The following is a timestamp interface that is commonly used in project development, which can be used directly. First, related interfaces Second, the code implementation Third, test It is relatively ...
1. Related concepts DateTime.Ticks: 0001 represents 100 nanoseconds since midnight on January 1 12:00:00 experienced that Ticks property is 100 nanoseconds (1Ticks = 0.0001 ms). Unix timestamp: is the...
Timestamp The concept of no time zone Unix timestamp: refers to the total seconds of seconds from January 01, January 01, 1970 (00:00 on January 01, 1970 (08:00 00 seconds on January 01, 1970). DateTi...
There are two common storage methods for storage time under linux. One is how many seconds have elapsed since 1970. One is to use a structure to store the year, month, day, minute, minute,...
Just use this _ltoa_s function, where 13 represents the length of time_stamp, and 10 represents decimal. The timestamp is 12 numbers, so create a char with a length of 13 to prevent memory overflow...