3 years, 9 months ago.

Setting the date and time

Hi, Setting the date and time on my current board seems to be giving me anomalous results. I'm fairly new to this and so the error could be something simple.

So I started looking around and found this code provided:

  1. include "mbed.h"

int main() {

get the current time from the terminal struct tm t; printf("Enter current date and time:\n"); printf("YYYY MM DD HH MM SS[enter]\n"); scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday , &t.tm_hour, &t.tm_min, &t.tm_sec);

adjust for tm structure required values t.tm_year = t.tm_year - 1900; t.tm_mon = t.tm_mon - 1;

set the time set_time(mktime(&t));

display the time while(1) { time_t seconds = time(NULL); printf("Time as a basic string = %s", ctime(&seconds)); wait(1); } }

After running this code with the input 1995/10/25 12 33 42 I got the attached screenshot saying the year is in the future which confuses me greatly.

If anyone clear this up it would be greatly appreciated.

Cheers Josh /media/uploads/jbevan4/putty_2016-05-01_18-15-02.png

Are the slashes in the date correct?

posted by Mike G 12 May 2016
Be the first to answer this question.