In this example we will learn how to Display current date and time using C++.
#include<iostream> #include<cmath> #include <ctime> using namespace std; int main() { time_t t = time(NULL); tm* timePtr = localtime(&t); cout << "seconds= " << (timePtr->tm_sec) << endl; cout << "minutes = " << (timePtr->tm_min) << endl; cout << "hours = " << (timePtr->tm_hour) << endl; cout << "day of month = " << (timePtr->tm_mday) << endl; cout << "month of year = " << (timePtr->tm_mon)+1 << endl; cout << "year = " << (timePtr->tm_year)+1900 << endl; cout << "weekday = " << (timePtr->tm_wday )<< endl; cout << "day of year = " << (timePtr->tm_yday )<< endl; cout << "daylight savings = " <<(timePtr->tm_isdst )<< endl; cout << endl; cout << endl; cout << "Date " <<(timePtr->tm_mday)<<"/"<< (timePtr->tm_mon)+1 <<"/"<< (timePtr->tm_year)+1900<< endl; cout << "Time " << (timePtr->tm_hour)<<":"<< (timePtr->tm_min)<<":"<< (timePtr->tm_sec) << endl; return 0; } /* OUTPUT seconds= 6 minutes = 32 hours = 17 day of month = 4 month of year = 7 year = 2016 weekday = 1 day of year = 185 daylight savings = 1 Date 4/7/2016 Time 17:32:6 */
- C++ Simple Programs And Examples
- C++ – Hello World Program
- C++ – Simple calculator
- C++ – Even and Odd
- C++ – Swap two numbers
- C++ – Prime Number
- C++ – Find Perfect Number
- C++ – Factorial of Number
- C++ – Fibonacci Series
- C++ – Human Resource Management Program
- C++ – Calculate number of characters, words, sentences
- C++ – Subtract two Strings
- C++ – Processing of the Students structure
- C++ – Program with Matrices
- C++ – Calculate Equation
- C++ – Arrange Numbers in Ascending order
- C++ – Check Armstrong Number
- C++ – HCF and LCM
- C++ – Square Root of a Number
- C++ – Cube Root of a Number
- C++ – ASCII Code for Characters and numbers
- C++ – Check Palindrome Number
- C++ – Bubble sort
- C++ – Random Number Generator
- C++ – Sum of ODD Numbers in the Given Range
- C++ – Display current date and time
- Formula Based Programs
- C++ – Leap Year
- C++ – Surface Area and volume of cone
- C++ – Solve Quadratic equation
- String Based Programs
- C++ – String into Upper case or lower case
- C++ – Concatenate Strings
- Array Based Programs
- C++ – Program with Matrices
- Print Any Patterns
- C++ – Print 5 rows of 10 Stars (*)
- C++ – Half Pyramid of Stars (*)
- C++ – Half Pyramid of numbers
- C++ – Print Triangle of Stars
- C++ – Display Reverse pyramid.
- C++ – Print Alphabet Pattern
- C++ – Diamond of Star
- C++ – Pascal Triangle
- C++ – Floyd Triangle
- C++ Conversion
- C++ – Convert decimal to Hexadecimal
- C++ – Decimal to Binary
- C++ Sorting algorithms & Techniques
- C++ – Bubble Sort
- C++ – Insertion Sort
- C++ – Selection Sort
- C++ – Merge Sort
- C++ – Quick Sort
- C++ Handling Files
- C++ – How to get Current Directory in Linux/Windows
- C++ – How Create a Text File and Write in It
I haven’t tested if the program runs-for theory part; refer to http://www.scitechtop.com
I don’t know if you 2 are same persons..your design is same so..