C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 6th, 2003, 02:08 AM
aleezah aleezah is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 15 aleezah User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
time...without seconds in C!!

hi!
well i had been able to figure out how to get time in hours and minutes..not the seconds.....
the following code gives me time as...10:30:23...hh:mm:sec
i want only hh:min
can anyone sugest how i can do this
#include <time.h>
#include <stdio.h>

#define SIZE 256

int
main (void)
{
char buffer1[SIZE];
char buffer2[SIZE];
time_t curtime;
struct tm *loctime;

/* Get the current time. */
curtime = time (NULL);

/* Convert it to local time representation. */
loctime = localtime (&curtime);


/* Print out the date and time in the standard format. */
fputs (asctime (loctime), stdout);

/* Print it out in a nice format. */
strftime (buffer1, SIZE, " %x\n", loctime);
printf("date: %s\n",buffer1);

strftime (buffer2, SIZE, "%X", loctime);
printf("time: %s\n",buffer2);

return 0;
}

Reply With Quote
  #2  
Old May 6th, 2003, 09:44 AM
dwise1_aol's Avatar
dwise1_aol dwise1_aol is online now
Contributing User
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jan 2003
Location: USA
Posts: 3,803 dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)dwise1_aol User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 1 Month 11 h 56 m 57 sec
Reputation Power: 437
Check out the other format specifiers on the man page for strftime (or in the help file entry for strftime).

Quote:
abbridged
%H The hour as a decimal number using a 24-hour clock
(range 00 to 23).

%I The hour as a decimal number using a 12-hour clock
(range 01 to 12).

%k The hour (24-hour clock) as a decimal number (range
0 to 23); single digits are preceded by a blank.
(See also %H.) (TZ)

%l The hour (12-hour clock) as a decimal number (range
1 to 12); single digits are preceded by a blank.
(See also %I.) (TZ)

%M The minute as a decimal number (range 00 to 59).

%n A newline character. (SU)

%O Modifier: use alternative format, see below. (SU)
value, or the corresponding strings for the current
locale. Noon is treated as `pm' and midnight as
`am'.

%P Like %p but in lowercase: `am' or `pm' or a corre_
sponding string for the current locale. (GNU)

%r The time in a.m. or p.m. notation. In the POSIX
locale this is equivalent to `%I:%M:%S %p'. (SU)

%R The time in 24-hour notation (%H:%M). (SU) For a
version including the seconds, see %T below.

%s The number of seconds since the Epoch, i.e., since
1970-01-01 00:00:00 UTC. (TZ)

%S The second as a decimal number (range 00 to 61).

%t A tab character. (SU)

%T The time in 24-hour notation (%H:%M:%S). (SU)

There are lots more options that look interesting, so I recommend reading it yourself.

BTW, thanks. I had never looked at strftime before.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > time...without seconds in C!!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway