我正在开发GPS项目,为此我想在每次接收GPS数据后添加时间戳(UTC)。我如何将IST转换为C中的UTC?我将tv.tv_sec减去5:30小时,但这不是正确的方法。是否有任何功能从IST获取UTC?如何在C(Ubuntu)中将IST时间转换为UTC时间?
#define MAX_STRING_SIZE 50 /* for TimeStampsForServer */
int fnTimeStampsForGpsData()
{
struct timeval tv;
struct tm *ptm;
char TimeString[MAX_STRING_SIZE];
long MicroSeconds;
/**
* Obtain the time of day, and convert it to a tm struct.
*/
gettimeofday (&tv, NULL);
tv.tv_sec -= 19800; /* Number of seconds (5:30) */
ptm = localtime (&tv.tv_sec);
/**
* Format the date and time, down to a single second.
*/
strftime (TimeString, sizeof (TimeString), "%Y-%m-%d %H:%M:%S", ptm);
/**
* Copying microseconds.
*/
MicroSeconds = tv.tv_usec;
/**
* Print the formatted time, in seconds, followed by a decimal point
* and the microseconds.
*/
printf ("%s.%06ld\n", TimeString, MicroSeconds);
return 0;
}