Skip to main content
AAnju.1
Visitor II
September 24, 2020
Question

Add date time offset (set time Zone)

  • September 24, 2020
  • 2 replies
  • 1998 views

Hi

Iam using CUBEMX and kiel for my development. iam read date time from the GSM modem

when i read it from the modem its looks like this.

+QLTS: "20/09/24,18:08:18+22,0"

+22 mean my time zone(+5:30). my actual time at this time is

2020:09:24 23:38:20

i will extract year, month..... from the above string and pass it into another function

void update_Internal_RTC(Time_t set_time){
	
 	
 RTC_TimeTypeDef set_Time = {0};
 RTC_DateTypeDef set_Date = {0};
		
 set_Time.Hours = set_time.Hour;
 set_Time.Minutes = set_time.Minute;
 set_Time.Seconds = set_time.Second;
 
 if (HAL_RTC_SetTime(&hrtc, &set_Time, RTC_FORMAT_BIN) != HAL_OK)
 {
 Error_Handler();
 }
	
 set_Date.Month = time.Month;
 set_Date.Date = time.Date;
 set_Date.Year = time.Year;
 printf("year is %d\r\n",time.Year);
 if (HAL_RTC_SetDate(&hrtc, &set_Date, RTC_FORMAT_BIN) != HAL_OK)
 {
 Error_Handler();
 }
	
	 	
}

now i want to add my time offset before sent it to RTC module. simply i need add 19800 (5:30) seconds before save it on the timer. what is the simplest way

Greetings

This topic has been closed for replies.

2 replies

waclawek.jan
Super User
September 24, 2020

The simplest way is to convert the time to seconds in some epoch, add seconds, and convert time back. Use the standard C library functions prototyped in <time.h>.

JW

Tesla DeLorean
Guru
September 24, 2020

Decide what time you want to use in your system, and then stick with it, and do conversions as necessary.

Personally, I'd stick with ZULU time (GMT/UTC), and remember the current time zone, I live in a country spanning multiple zones.

When I need a LOCAL time stamp, I'd convert into that, and use that to generate TIME and DATE

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..