0

I'm quite new, What I'm aiming for is something like: Saturday, January 29, 2022 and this is what I currently have:

#include <stdio.h>
#include <sys/sysinfo.h>
#include <time.h>



int main(void) {
  time_t currentTime;
  time(&currentTime);

  printf("%s\n", ctime(&currentTime));  
 


return 0;
}
BionicEdit
  • 25
  • 3
  • 1
    Check this one [strftime](https://en.cppreference.com/w/cpp/chrono/c/strftime) – pvc Jan 29 '22 at 14:53

1 Answers1

0

You can use localtime and strftime.

Example:

#include <stdio.h>
#include <time.h>

int main(void) {
    time_t currentTime;
    char result[64];

    time(&currentTime);
    size_t len = strftime(result, sizeof result, "%A, %B %d, %Y",
                          localtime(&currentTime));
    if(len != 0)
        printf("result = %s\n", result);

    printf("length of result = %zu\n", len);
}

Possible output:

result = Saturday, January 29, 2022
length of result = 26
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108