Solved

time/day and C only

Posted on 2001-06-30
2
190 Views
Last Modified: 2010-04-21

I want to make a greeting, in Linux (C program only)like

if hour is > 18PM and < 22PM
print "good evening, today is Wednesday. in year 2001 has 200 days remaining, time now is %s", time$);

if hour is > 4AM and <8AM
print "good morning, today is Friday. in year 2001 has 172 days remaining, time now is %s", time$);

0
Comment
Question by:16bits
2 Comments
 
LVL 8

Accepted Solution

by:
mnashadka earned 50 total points
ID: 6241458
Try something like:
time_t now;
struct tm *time_struct;
char day_str[20];
char time_str[20];

now = time(NULL);
time_struct = mktime(&now);

strftime(day_str, 20, "%a", time_struct);
strftime(time_str, 20, "%H:%M:%S", time_struct);

if(time_struct->
tm_hour > 18 && time_struct->tm_hour < 22)
{
  printf("Good evening, today is %s in year %d, it is the %d day of the year, time now is %s", day_str, time_struct->tm_year, time_struct->yday, time_str);
}
else if(time_struct->
tm_hour > 4 && time_struct->
tm_hour < 8)
{
  printf("Good morning, today is %s in year %d, it is the %d day of the year, time now is %s", day_str, time_struct->tm_year, time_struct->yday, time_str);
}

Note, this doesn't give you the number of days remaing.  To do this, you need to figure out the number of days in the year and subtract time_struct->yday from that.  Hope this helps.    
0
 

Author Comment

by:16bits
ID: 6241637
it actually helps a lot, thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Centos Boot Error 42 116
need help to replace faulty disk using lv mirroring 18 164
partition customisation for kickstart file 2 92
What is the timeframe of this cron job? 2 131
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now