Sometimes when I work on my projects, I need to get the current date and time. Basically this can be achieved by using a RTC or NTP server. But when none of this options can be used, the simplest way I found, is to use a simple url request from a server. In my case I use a GSM/GPRS that dosen't have NTP protocol and the RTC can't be used because the module will be power off in some conditions. I don't use the GSM time because it take to too much time to make the synchronization with the GSM network and I want to be independent form GSM network time.

So, I create a simple api to get the time and date using a url request. The timezone is a parameter that need to be introduced like: America/Adak, Europe/Paris, etc.

http://cmn-lab.com/api/dt?zone=timezone

The returned value will be in this format: hours,minutes,seconds,day,month,year
All I need is to parse the returned text and subtract the values.

However you can use the method for your projects as well, because I will keep this url for long time knowing that I already deployed some project that depends on this url.

Categories: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *