主题中讨论的其他器件:CC1352P7
您好!
我正在一个项目中工作。 为此、我需要每秒使用一个时间戳(传感器读取时间)。 我举一个例子,互联网是下面给出。
#include <time.h>
#include <ti/sysbios/hal/Seconds.h>
#include <ti/drivers/dpl/ClockP.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <unistd.h>
#include <stdio.h>
char risp[40];
String args = "2023-10-03 15:48:00";
String getTime()
{
struct tm *ltm;
time_t now;
now = time(NULL);
ltm = gmtime(&now);
memset(risp,0, strlen(risp));
strftime(risp, 40, "%d/%m/%y-%H:%M:%S", ltm);
// printf("%s\r\n",risp);
return risp;
}
void setTime()
{
struct tm ltm;
memset(<m, 0, sizeof(struct tm));
if( sscanf(args, "%d-%d-%d %d:%d:%d", <m.tm_year, <m.tm_mon, <m.tm_mday, <m.tm_hour, <m.tm_min, <m.tm_sec) == 6 )
{
ltm.tm_year -= 1900;
ltm.tm_mon -= 1;
ltm.tm_isdst = 1;
_tz.timezone = 0;
time_t newTime = mktime(<m);
Seconds_set(newTime - 2208988800); //ATTENTION!!
}
}
在这里,我唯一的问题是:当我从 gettime ()函数读取时间。 没有获得正确的日期。 我将提前一天预定日期。 而不是今天的日期,我得到明天的日期,而是从 gettime 函数读它。没有问题与时间。 问题仅在于日期。
2天后出现此问题。
时区 :印度时间 。 我认为这里不需要使用时区。
你能帮我吗?