C/C++ : Get Current Time

Using Matlab, we can get the current date and time using “now” command.  Example, using Matlab  we can use below command :

How if we want to get current time using C/C++ with the result like Matlab ?

We can use “localtime” to get date and time in C/C++  and use gettimeofday to get time in milisecon. The complete code how to get current time in C/C++ is :

Compile the code using command :

The sample running execution program is :


Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.