LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-14-2012, 08:45 AM   #1
suttiwit
Member
 
Registered: Aug 2012
Location: Chiang Mai, Thailand
Distribution: Kubuntu 12.10 x86_64
Posts: 192
Blog Entries: 2

Rep: Reputation: 22
Wink Questions related to time and date in C.


Hello, I have 2 questions related to time and date in the C Programming Language.
Here:
1. How can I translate the output from time(NULL); to the human readable time and (if possible) date?
2. How can I get the date and time from the BIOS or the Hardware Clock and if needed translate it to human readable time and date?

Help would be appreciated.

Also, I am really happy with LinuxQuestions.org. It is the only place to ask Linux and Programming Stuff for me because people at my country don't use linux or program.
 
Old 09-14-2012, 08:54 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,436
Blog Entries: 11

Rep: Reputation: 181Reputation: 181
http://www.codingunit.com/c-tutorial...-and-date-in-c

ctime()
mktime()

console:
Code:
# man ctime
To have the man page for date time related C functions.
 
1 members found this post helpful.
Old 09-14-2012, 02:49 PM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,727

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
or: localtime + strftime
 
Old 09-14-2012, 05:30 PM   #4
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 2,746

Rep: Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976Reputation: 976
A quick example:

Code:
time_t mytime;
struct tm * ptm;

mytime = time(NULL);
ptm = gmtime(&mytime);
printf("%03i, %04i %02i:%02i\n",ptm->tm_yday+1,ptm->tm_year+1900,ptm->tm_hour,ptm->tm_min);

Last edited by suicidaleggroll; 09-14-2012 at 05:35 PM.
 
Old 09-15-2012, 12:00 AM   #5
suttiwit
Member
 
Registered: Aug 2012
Location: Chiang Mai, Thailand
Distribution: Kubuntu 12.10 x86_64
Posts: 192
Blog Entries: 2

Original Poster
Rep: Reputation: 22
How 'bout: how do I convert the Human Readable time and date in a format and convert it to Epoch. Thanks all.
 
Old 09-15-2012, 12:12 AM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,727

Rep: Reputation: 488Reputation: 488Reputation: 488Reputation: 488Reputation: 488
It is already in a format, and what do you mean by 'Epoch'?
PS: strptime is your friend.
 
  


Reply

Tags
c++, gcc, linux, time, unix


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date comparison with 'string date having slashes and time zone' in Bash only TariqYousaf Programming 2 10-08-2009 07:37 AM
how to convert windows date and time to unix date and time jitupatil_2007 General 8 03-31-2008 05:58 AM
Setting system date and time affecting the clock and date on BIOS satimis Ubuntu 7 09-21-2007 08:02 AM
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM


All times are GMT -5. The time now is 06:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration