Solved

time/day and C only

Posted on 2001-06-30
2
197 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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