JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

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

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi sociology physics physical education maths english economics geography History

chemistry business studies biology accountancy political science

Class 12

Hindi physics physical education maths english economics

chemistry business studies biology accountancy Political science History sociology

Home science Geography

English medium Notes

Class 6

Hindi social science science maths English

Class 7

Hindi social science science maths English

Class 8

Hindi social science science maths English

Class 9

Hindi social science science Maths English

Class 10

Hindi Social science science Maths English

Class 11

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Class 12

Hindi physics physical education maths entrepreneurship english economics

chemistry business studies biology accountancy

Categories: c++ language in hindi

write a program to write current time of system , using ctime() , gmtime() , use difftime ()

using ctime() , gmtime() , use difftime () , write a program to write current time of system :-
इससे पहले के article मे time class और date class को discuss किया है अब इस article मे ctime header file के functions के उदाहरन को discuss करेगे जिससे इन सभी function के syntax को अच्छी तरह से समज सके |उदहारण -1
write a program to write current time of system.

Explanation
इस उदहारण मे time_t time(time_t *time)को use किया जाता है |इस function से कंप्यूटर सिस्टम के current calendar time को return किया जाता है |
सबसे पहले struture को declare किया जाता है जिसमे current time store होता है |
उसके बाद इस time struture के sec मे  time_t time(time_t *time)से return की गयी time को return किया जाता है |
उससके बाद sec की value को display किया जाता है |

source code
#include <iostream>
#include<conio.h>
#include <ctime>
using namespace std;
int main()
{
time_t sec;
sec = time( ) ;
cout << “The current time in second :”<< sec << endl;
}

इस उदाहरन मे current सिस्टम के time को 1 jan 1970 से अब तक के time को second मे convert करके assign किया जाता है | ओए इसके बाद print किया जाता है |

इसका आउटपुट होगा :
The current time in second : 15381986587

उदहारण -2
write a program to write current time of system using ctime().

Explanation
इस उदहारण मे ctime() को use किया जाता है |इस function से कंप्यूटर सिस्टम के current calendar time को return किया जाता है |  लेकिन in function को string मे assign किया जाता  है |
सबसे पहले struture को declare किया जाता है जिसमे current time store होता है |
उसके बाद इस time struture मे  time_t time(time_t *time)से return की गयी time को return किया जाता है |
उससके बाद  cout statement मे ctime() मे  struture को pass किया जाता है | और string form मे time को  day month year hours:minutes:seconds year को display किया जाता है |

source code
#include <iostream>
#include<conio.h>
#include <ctime>
using namespace std;
int main()
{
time_t sec;
sec = time() ;
cout << “The current time in string form  :”<< ctime(sec) << endl;
}

इस उदाहरन मे current सिस्टम के time को 1 jan 1970 से अब तक के time को second मे convert करके assign किया जाता है | उसके बाद ctime() से string को  print किया जाता है |

इसका आउटपुट होगा :
The current time in second : Monday 12 2019 06:12:56 2019

उदहारण -3
write a program to write current time of execution of function.

Explanation
इस उदहारण मे clock(void) को use किया जाता है |इस function मे लगा time को return किया जाता है |
सबसे पहले struture को declare किया जाता है जिसमे current time store होता है |
उसके बाद इस time struture के time मे  clock(function_name)से return की गयी time को return किया जाता है |
उससके बाद time की value को display किया जाता है |

source code
#include <iostream>
#include<conio.h>
#include <ctime>
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;
} tm;
using namespace std;
int main()
{
tm time ;
time.tm_sec=10;
time.tm_min=10;
time.tm_hour=4;
time.tm_mday=25;
time.tm_mon=2;
time.tm_year=89;
time.tm_wday=6;
puts(acstime(time));
}

इसका आउटपुट होगा :
sat Mar 25 06:10:10 1989

उदहारण -4
write a program to use gmtime() .

Exaplanation
इस उदहारण मे gmtime() को use किया जाता है |इस function से कंप्यूटर सिस्टम के current calendar time को  UTC मे convert करके  return किया जाता है |
सबसे पहले struture time को declare किया जाता है जिसमे current time store होता है |
उसके बाद  struture time को  gmtime() मे pass किया जाता है  |
उससके बाद gmtime() से मिले value को london और canada के time मे convert करके print किया जाता है |

source code
#include <iostream>
#include<conio.h>
#include <ctime>
using namespace std;
int main()
{
time_t sec;
sec = time( ) ;
struct time ;
time gmtime(sec);
cout<<“Current time in india :”<<(time.tm_hour)%24 <<“.”<<time.tm_min <<endl;
cout<<“Current time in london :”<<(time.tm_hour + 1 )%24 <<“.”<<time.tm_min <<endl;
cout<<“Current time in canada :”<<(time.tm_hour – 6)%24 <<“.”<<time.tm_min <<endl;
}

इसका आउटपुट होगा :
Current time in india : 12.12
Current time in london : 13.12
Current time in canada : 6.12

उदहारण -5
write a program to use difftime () .

Explanation
इस उदहारण मे difftime () को use किया जाता है |इस function का use किसी दो time जोन के बीच difference को calculate करने में किया जाता है  |
सबसे पहले एक struture variable time मे current time को assign करा देते है |
इसके बाद एक और variable मे सिस्टम को reboot करने एक time को manual add करते है |
इसके बाद difftime() से time difference को calcualate किया जाता है |
ऑर्ट इस time difference को print किया जाता है |

source code
#include <iostream>
#include<conio.h>
#include <ctime>
using namespace std;
int main()
{
tm time ;
time.tm_sec=10;
time.tm_min=10;
time.tm_hour=4;
time.tm_mday=25;
time.tm_mon=2;
time.tm_year=89;
time.tm_wday=6;
tm current ;
current = time () ;
int *sec = difftime (time , current );
cout<<“Reboot time :”<<ctime(sec)<<endl;
getch();
}

Sbistudy

Recent Posts

द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन क्या हैं differential equations of second order and special functions in hindi

अध्याय - द्वितीय कोटि के अवकल समीकरण तथा विशिष्ट फलन (Differential Equations of Second Order…

54 mins ago

four potential in hindi 4-potential electrodynamics चतुर्विम विभव किसे कहते हैं

चतुर्विम विभव (Four-Potential) हम जानते हैं कि एक निर्देश तंत्र में विद्युत क्षेत्र इसके सापेक्ष…

3 days ago

Relativistic Electrodynamics in hindi आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा

आपेक्षिकीय विद्युतगतिकी नोट्स क्या है परिभाषा Relativistic Electrodynamics in hindi ? अध्याय : आपेक्षिकीय विद्युतगतिकी…

5 days ago

pair production in hindi formula definition युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए

युग्म उत्पादन किसे कहते हैं परिभाषा सूत्र क्या है लिखिए pair production in hindi formula…

1 week ago

THRESHOLD REACTION ENERGY in hindi देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा

देहली अभिक्रिया ऊर्जा किसे कहते हैं सूत्र क्या है परिभाषा THRESHOLD REACTION ENERGY in hindi…

1 week 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