asctime() in C++

asctime(): This function returns the current time of the system.

This function returns the time in format Www Mmm dd hh:mm: ss yyyy

Www - It is the weekday. It takes any value from {"Mon","Tue","Wed","Thu","Fri","Sat","Sun"}

Mmm - It is the month (in letters).

dd- It is the day of the month.

hh:mm: ss the time.

hh- It represents an hour. It ranges from [00,23]

mm- It represents minutes. It ranges from [00,59]

ss - It represents second. It ranges from [00,59]

yyyy -It represents  the year. 

This function is available in the below file.

File: time.h

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{

    time_t rawtime;
    struct tm *timeinfo;

    time(&rawtime);
    timeinfo = localtime(&rawtime);

    cout << asctime(timeinfo<< "\n";

    return 0;
}


No comments:

Post a Comment