हिंदी माध्यम नोट्स
c++ : time class in hindi , what is time class in c++ language with program example source code & explanation
struture type tm का use date और time को struture के elements store करने के लिए किया जाता है | इस struture मे निन्म elements होते है :
int tm_sec; : इसमें time के second की value को store किया जाता है | इसके range 0 से 61 होती है
int tm_min; : इसमें time के minutes की value को store किया जाता है | इसके range 0 से 59 होती है
int tm_hour; : इसमें time के hour की value को store किया जाता है | इसके range 0 से 24 होती है
int tm_mday; : इसमें month के day की value को store किया जाता है | इसके range 1 से 31 होती है
int tm_mon; : इसमें year के month की value को store किया जाता है | इसके range 1 से 12 होती है
int tm_year; : इसमें year की value को store किया जाता है | इसके range 1900 से शुरू होती है
int tm_wday; : इसमें days की value को store किया जाता है | इसके range sunday से शुरू होती है
int tm_yday; : इसमें days की value को store किया जाता है | इसके range 100 से शुरू होती है
int tm_isdst;: इसमें hours of daylight savings time की value को store किया जाता है |
इसका struture निन्म होता :
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}
c++ language मे निन्म functions होता है जिसका use date और time को handle करता है | ये सभी function c और c++ standard library मे store होता है
|इस article मे in function को भी discuss करगे :-
1.time_t time(time_t *time);
इस function से कंप्यूटर सिस्टम के current calendar time को return किया जाता है | इसमें seconds की form मे time return होता है | अगर कंप्यूटर सिस्टम मे कोई भी time नहीं होता है तब ‘1’ return होता है | time January 1, 1970 से शुरू होता है |
2.char *ctime(const time_t *time);
इस function से string का pointer return होता है जो की day month year hours:minutes:seconds year form मे time को return करता है |
3.struct tm *localtime(const time_t *time);
इस function से local time को struture की form मे return किया जाता है |
4.clock_t clock(void);
इस function से किसी function को call करने में लगा समय को return किया जाता है | अगर time available नहीं है तब ‘1’ return होता है |
5.char * asctime ( const struct tm * time );
इस function से string form का pointer return होता है जो की किस time को day month date hours:minutes:seconds year\n\0 रूप मे struture मे store करता है |
6.struct tm *gmtime(const time_t *time);
इस function से time को tm structure मे return किया जाता है | time को Universal Time (UTC)मे convert किया जाता है | जो की Greenwich Mean Time (GMT)जरुरी है |
7.time_t mktime(struct tm *time);
इस function से time को return किया जाता है | time को structure की form मे return किया जाता है |
8.double difftime ( time_t time2, time_t time1 );
इस function का use time1 and time2 मे difference को calculate किया जाता है |
9.size_t strftime();
इस function का use date और time को किसी format मे return किया जाता है |
Current Date and Time
इस प्रोग्राम मे ,current system date और time को local time orCoordinated Universal Time (UTC) की form मे display किया जाता है |
Source code :
#include <iostream>
#include<conio.h>
#include <ctime>
using namespace std;
int main()
{
time_t now = time(0); // Current time
char* dt = ctime(&now); // convert time into string pointer
cout << “The local date and time is: ” << dt << endl;
tm *gmtm = gmtime(&now); //convert time to tm struct for UTC
dt = asctime(gmtm);
cout << “The UTC date and time is:”<< dt << endl;
}
जब उपर वाले प्रोग्राम को excute किया जाता है तब इसका आउटपुट होगा :
The local date and time is: Sat Jan 8 20:07:41 2019
The UTC date and time is:Sun Jan 9 03:07:41 2019
Format Time using struct tm
इस struture मे date और time को add किया जाता है | जब इस struture को use किया जाता है तब इसक उदाहरन निन्म होता है :
इस उदहारण मे time_t now मे सिस्टम का current time को assign किया जाता है | और pointer ltm मे now को local time मे convert करके assign किया जाता है | इसका source code निन्म है :-
source Code
#include <iostream>
#include <ctime>
using namespace std;
int main() {
time_t now = time(0);
cout << “Number of sec since January 1,1970:” << now << endl;
tm *ltm = localtime(&now);
cout << “Year” << 1970 + ltm->tm_year<<endl;
cout << “Month: “<< 1 + ltm->tm_mon<< endl;
cout << “Day: “<< ltm->tm_mday << endl;
cout << “Time: “<< 1 + ltm->tm_hour << “:”;
cout << 1 + ltm->tm_min << “:”;
cout << 1 + ltm->tm_sec << endl;
}
When the above code is compiled and executed, it produces the following result −
Number of sec since January 1, 1970:1294548238
Year: 2019
Month: 1
Day: 8
Time: 22: 44:59
Recent Posts
सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है
सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…
मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the
marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…
राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi
sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…
गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi
gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…
Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन
वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…
polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten
get all types and chapters polity notes pdf in hindi for upsc , SSC ,…