Date And Time In Hindi

C++ Date & Time In Hindi

C++

C++ Date And Time In HindiDate And Time Function In C++ In Hindi Ko Ham Learn Karne Wale Hai Or Date Time Function Ko Bhi Dekhne Wale Hai |

Also Read – C++ Data Structures

C++ Date & Time Functions In Hindi

Date And Time Function Ka Istemal Karne Ke Liye Aapko header Me include <ctime> Karna Hoga |

<ctime> Ke Under Four time Related Functions Hote Hai – tm, clock_t, time_t, and size_t.

“tm” Structure – Har Ek Types clock_t, time_t, and size_t. represent Karta Hai System Ki Time And Date Ko Integer Ke Rup Me And Date OR Time Ko Structure Ke Rup Me Hold Karta Hai tm |

struct tm
 {
                  int tm_sec; // seconds of minutes from 0 to 61
                  int tm_min; // minutes of hour from 0 to 59
                  int tm_hour; // hours of day from 0 to 24
                  int tm_mday; // day of month from 1 to 31
                  int tm_mon; // month of year from 0 to 11
                  int tm_year; // year since 1900
                  int tm_wday; // days since sunday
                  int tm_yday; // days since January 1st
                  int tm_isdst; // hours of daylight savings time
 }

Date And Time Functions in Hindi

Date And Time Ko Represent Karne Hai Jo Niche Diye Gaye Functions Hai. Aap Niche Diye Gaye Functions Ko Acchi Tarah Se Understand Kar Sakte Hai |

Function NameFunction PrototypeDescription
ctimechar *ctime(const time_t *time);Returns a pointer to a string in the form weekday month date hours:minutes: seconds year.
gmtimestruct tm *gmtime(const time_t *time);Returns pointer to the tm structure in the Coordinated Universal Time (UTC) format which is essentially Greenwich Mean Time (GMT).
localtimestruct tm *localtime(const time_t *time);Returns pointer to tm structure representing local time.
strftimesize_t strftime();Used to format date and time in specific format.
asctimechar * asctime ( const struct tm * time );Converts time object of type tm to string and returns a pointer to this string.
timetime_t time(time_t *time);Returns current time.
clockclock_t clock(void);Returns an approximate value for the amount of time the calling program has been running. A value of .1 is returned if the time is not available.
difftimedouble difftime ( time_t time2, time_t time1 );Returns difference between two time objects time1 and time2.
mktimetime_t mktime(struct tm *time);Converts tm structure to time_t format or calendar equivalent.

Example:

The following code Example calculates the current time in local and GMT format and displays it.

#include <iostream>
#include <ctime>
using namespace std;
 
int main( )
 {
    
  time_t ttime = time(0);

  char* dt = ctime(&ttime);
  cout << "The current local date and time is: " << dt << endl;

  tm *gmt_time = gmtime(&ttime);
  dt = asctime(gmt_time);
  cout << "The current UTC date and time is:"<< dt << endl;
 }

Output:

The current local date and time is: Fri Aug 28 15:03:19 2020

The current UTC date and time is:Fri Aug 28 15:03:19 2020

Format Time using struct tm

#include <iostream>
#include <ctime>

using namespace std;

int main() {
   // current date/time based on current system
   time_t now = time(0);

   cout << "Number of sec since January 1,1970:" << now << endl;

   tm *ltm = localtime(&now);

   // print various components of tm structure.
   cout << "Year:" << 1900 + 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;
}

Output:

Number of sec since January 1,1970 is:: 1598626960
Year:2020
Month: 8
Day: 28
Time: 20:32:40

Also Read – Arrays – Lists of Data & Multidimensional Arrays

Friends Mujhe Umeed Hai Ki Aapko CPP Date And Time Functions In Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *