JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

c++ : time class in hindi , what is time class in c++ language with program example source code & explanation

what is time class in c++ language with program example source code & explanation , c++ : time class in hindi :-
c++ language मे  proper date type नहीं है | c++ language मे , date को implement करनेके लिए struture और function को use किया जाता है | अतः जब किसी date और time को प्रोग्राम मे use करने के लिए ctime header file को use किया जाता है | ctime header file को declartion region से activeness को बनाया जाता है | जब कसी ctime को header region मे include किया जाता है | तब इस header file मे define किये गये function और struture को पुरे main() और यूजर define function और class मे use किया जा सकता है | जब ctime header file को किसी main() , user define function और class मे include किया जाता है तब इस header file मे define function और struture को केवल define region मे use किया जासकता है |c++ language मे चार time related types : clock_t, time_t, size_t, and tm. को define किया गया है | इन type – clock_t, size_t and time_t से date और time को integer form मे assign किया जाता है | यानी सबसे पहले date और time को integer form मे convert किया जाता है तब इन value को struture के member मे assign किया जाता है |
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

Sbistudy

Recent Posts

Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic

Question Tag Definition • A question tag is a small question at the end of a…

3 weeks ago

Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)

Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…

3 weeks ago

Report Writing examples in english grammer How to Write Reports explain Exercise

Report Writing • How to Write Reports • Just as no definite rules can be laid down…

3 weeks ago

Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th

Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…

3 weeks ago

विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features

continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…

3 weeks ago

भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC

भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…

3 weeks ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now