[ create a new paste ] login | about

Link: http://codepad.org/KWFeOnDm    [ raw code | output | fork ]

slevy1ster - C, pasted on Jun 27:
#include <stdio.h>
#include <time.h>

typedef struct hour{
  int hour;
  int minute;
  int second;
  int isdst;
} Hour;

typedef struct date{
  int day;
  int month;
  int year;
  Hour hr;
} Date;

int main (void) {
  Date d;
  time_t now = time(0);
  struct tm temp;
  char buffer[80];
  const char *format = "%m-%d-%Y %H:%M:%S";

  // get current local date and time ...
  localtime_r( &now, &temp );

  // ... storing it in date structure  ...
  d.day       = temp.tm_mday;
  d.month     = temp.tm_mon;
  d.year      = temp.tm_year;
  d.hr.hour   = temp.tm_hour;
  d.hr.minute = temp.tm_min;
  d.hr.second = temp.tm_sec;
  d.hr.isdst  = temp.tm_isdst;

  // ... and may safely display  
  strftime (buffer, 80, format, &temp);
  printf("Current local date and time: %s",buffer);

  return(0);
}


Output:
1
Current local date and time: 06-27-2017 09:30:05


Create a new paste based on this one


Comments: