Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
C++ Tutorial
C++ Language Tutorial - Object Oriented Programing - OOPs History of C++
C++ Language Tutorial - Object Oriented Programing - OOPs Structure of C++
C++ Language Tutorial - Object Oriented Programing - OOPs C++ Datatypes
C++ Language Tutorial - Object Oriented Programing - OOPs Variables
C++ Language Tutorial - Object Oriented Programing - OOPs Constants
C++ Language Tutorial - Object Oriented Programing - OOPs Operators
C++ Language Tutorial - Object Oriented Programing - OOPs Control Structures
C++ Language Tutorial - Object Oriented Programing - OOPs Arrays
C++ Language Tutorial - Object Oriented Programing - OOPs Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Class
C++ Language Tutorial - Object Oriented Programing - OOPs Predefined Functions
C++ Language Tutorial - Object Oriented Programing - OOPs I/O Functions
C++ Language Tutorial - Object Oriented Programing - OOPs String, Character Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Mathematical Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Time Date Functions
C++ Language Tutorial - Object Oriented Programing - OOPs Dynamic Allocation
C++ Language Tutorial - Object Oriented Programing - OOPs Utility Functions
C++ Language Tutorial - Object Oriented Programing - OOPs OOP's Concept
C++ Language Tutorial - Object Oriented Programing - OOPs Special Topics
C++ Language Tutorial - Object Oriented Programing - OOPs Type casting
C++ Language Tutorial - Object Oriented Programing - OOPs Feedback
C++ Language Tutorial - Object Oriented Programing - OOPs Ask Your Doubts
 




mktime() - Time Date Function


Tutorials Cpp

Topic

How to convert date to calendar in C++?



Explanation

mktime() function converts the calendar time equivalent of the broken down structure pointed by "time". The "tm_wday", "tm_yday" elements are set by the function itself.

Syntax:
    time_t mktime(struct tm *time);

Example:

   #include <stdio.h>
   #include <time.h>
   int main ()
   {
      time_t tim;
      struct tm *ptr;
      int y = 2010, m = 2 ,d = 2;
      char * weekday[] = { "Sunday", "Monday", "Tuesday", 
             "Wednesday", "Thursday", "Friday", "Saturday"};
      time ( &tim );
      ptr = localtime ( &tim );
      ptr->tm_year = y - 1900;
      ptr->tm_mon = m - 1;
      ptr->tm_mday = d;
      mktime ( ptr );
      printf ("February 2, 2010 was a:: %s.\n", 
            weekday[ptr->tm_wday]);
      return 0;
   }

Result:
   February 2, 2010 was a:: Tuesday

In the above example "mktime()" is used to convert the "tm_wday" to find the weekday for the given date in calendar.










Note
C++ is one of the most used programming languages in the world. Also known as "C with Classes". Hope you enjoy this tutorial. Do send your feedback or suggestions on this C++ tutorial. This is a copyright content.

Other Links

web hosting