473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to determine curreent date and time/

I am using GCC on FEDORA.

I want to print current date an time. How can do that.

Thanks
-Sanchit
Jun 27 '08 #1
6 4367
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.

I want to print current date an time. How can do that.
system("date");

Jun 27 '08 #2
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.

system("date");
Oh I forgot to mention.. I want a C function for this.
Jun 27 '08 #3
On 14 Apr 2008 at 17:39, Sanchit wrote:
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
>On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.

system("date");

Oh I forgot to mention.. I want a C function for this.
strftime?

Jun 27 '08 #4
On 14 Apr, 19:14, Sanchit <sanchitgupt...@gmail.comwrote:
I am using GCC on FEDORA.

I want to print current date an time. How can do that.
#include <time.h>
#include <stdio.h>
#include <stdlib.h>

int main(){

time_t now = time(NULL);
struct tm *now_s = localtime(&now);

if(now_s == NULL)
return EXIT_FAILURE;

printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900+now_s->tm_year, ++now_s -
>tm_mon,
now_s->tm_mday, now_s->tm_hour, now_s->tm_min,now_s->tm_sec);

return EXIT_SUCCESS;
}

Bye.
Jun 27 '08 #5
>I am using GCC on FEDORA.
>
I want to print current date an time. How can do that.
In C, time() gets you the current date/time in a time_t format.
Various functions can get that into a printable string format:

ctime()
localtime() followed by strftime()
localtime() followed by asctime()
Jun 27 '08 #6
On Apr 14, 10:39 pm, Sanchit <sanchitgupt...@gmail.comwrote:
On Apr 14, 10:21 pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 14 Apr 2008 at 17:14, Sanchit wrote:
I am using GCC on FEDORA.
I want to print current date an time. How can do that.
system("date");

Oh I forgot to mention.. I want a C function for this.
http://www.cs.utah.edu/dept/old/texi...19.html#SEC320
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Gord | last post by:
Many scripts and calendars call client side system time in order to make presentations. However, the client's time may be improperly set, if set at all, and/or the relevant time may be from...
1
by: John Feeley | last post by:
am tring to add a number of years to a dob. im doing this by adding my date+years*365.26 I get a string of numbers. I then convert the number in the next column to actual date again. I'm getting...
3
by: Manny Chohan | last post by:
Guys, I have intranet application which our users use in offices all over the world. How can i retrieve the date and time on their pc and display it on the screen no matter what country they are...
0
by: Thomas Homan | last post by:
Hello, Is there a method in the FtpWebRequest that allows for preservation of the file being transferred original date and time in vs2005 vb? In the FTPSample the method is to set up stream...
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
21
by: rdemyan via AccessMonster.com | last post by:
Is there a way to get the internet date/time. I saw an article that uses WinSock, but WinSock doesn't seem to be available in Access. I want to verify that the date/time on the local PC running...
7
by: wanwan | last post by:
Hi, I'm looking for a better way to do a date/time elapsed event rather than a timer elapsed event. Currently, I wrote my program to use a timer elapsed event set to 1 second, and it checks...
4
by: Nathan Sokalski | last post by:
When determining whether a String can be converted to a DateTime, you can use the IsDate() method. However, I would also like to know whether the string is a date, a time, or both a date and a...
4
by: Matt.Russett | last post by:
Hello, Here is what I am trying to do. I am running a report that brings back Requested Pick-Up Times and Actual Pick-Up Times. What I want to measure is the amount of times the Requested...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.