Advertisement
dimipan80

Print Current Date and Time in Custom Format (better way!)

Oct 17th, 2015
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. /*
  2.  * Create a console application that prints the current date and time.
  3.  * (15 September 2015 16:25:17)
  4.  */
  5.  
  6. #include <stdio.h>
  7. #include <time.h>
  8.  
  9. int main()
  10. {
  11.     time_t t = time(NULL);
  12.     struct tm tm = *localtime(&t);
  13.     char timeString[50];
  14.  
  15.     strftime(timeString, sizeof(timeString) - 1, "%d %F %Y %H:%i:%s", tm);
  16.     printf("Current Date and Time is: %s\n", timeString);
  17.  
  18.     return (0);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement