Hello !
Here what I use to achieve that :
in my RT module, I have :
#include "rtlinux_gmtime_addon.h"
void display_date_time()
{
time_t time32bits;
struct tm * ptr_tm;
int dy,mh,yr,hr,mn,sc;
time(&time32bits);
ptr_tm = gmtime(&time32bits); /* from rt_linux_gmtime_addon.h
dy = ptr_tm->tm_mday;
mh = ptr_tm->tm_mon+1;
yr = ptr_tm->tm_year+1900;
hr = ptr_tm->tm_hour;
mn = ptr_tm->tm_min;
sc = ptr_tm->tm_sec;
rtl_printf("Date/Time : %02d/%02d/%02d-%02d:%02d:%02d\n",dy,mh,yr,hr,mn,sc);
}
I haven't succeded in using standart gmtime and mktime from the libc... if someone can
help?
>>> [EMAIL PROTECTED] 07/07/01 17h48 >>>
Hi Silva and all,
Thanks for the info.
I tried using do_gettimeofday but it is giving time in seconds and micro
seconds.
But my purpose is i need current time in some readable format, say,
HH:MM:SS
Similar way i need to get current date in some readable format say,
MM/DD/YY or DD/MM/YY or some other fomat.
Are there any RT Linux functions to retrieve or set the date and time in
the above specified formats.
Thanks,
sitaram
----- Original Message -----
From: Sergio Rui Silva <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 19, 2001 8:16 AM
Subject: Re: [rtl] Hi
> Yes it does. Besides suporting do_gettimeofday and do settimeofday it also
> suports reading and changing a variaty of other clocks like CLOCK_REALTIME
> and CLOCK_GPOS. Beware that RTLinux can use many kinds of clocks and that
if
> you want to read the system time (Linux time) you should use CLOCK_GPOS or
> do_gettimeofday.
>
> Sergio Rui Silva
>
> FEUP
>
> Em Sexta 06 Julho 2001 16:17, escreveste:
>
> > > Hi all,
> >
> > Does RT Linux support functions to set or get current date and time.
> >
> > Thanks,
> > Sitaram
> >
> > SMILE A LOT IT COSTS NOTHING
>
> ----------------------------------------
> Content-Type: text/html; charset="iso-8859-1"; name="Anexo: 1"
> Content-Transfer-Encoding: quoted-printable
> Content-Description:
> ----------------------------------------
> -- [rtl] ---
> To unsubscribe:
> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
> --
> For more information on Real-Time Linux see:
> http://www.rtlinux.org/
----- End of forwarded message from [EMAIL PROTECTED] -----
-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
--
For more information on Real-Time Linux see:
http://www.rtlinux.org/
#ifndef __RTLINUX_TIME_ADDON__
#define __RTLINUX_TIME_ADDON__
#include <time.h>
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
long int __tm_gmtoff;
__const char *__tm_zone;
};
static void __tm_conv(struct tm *tmbuf, time_t *timep, time_t offset);
static struct tm *gmtime(time_t *timep);
/* This is a translation from ALGOL in Collected Algorithms of CACM. */
/* Copied from Algorithm 199, Author: Robert G. Tantzen */
static void __tm_conv(tmbuf, timep, offset)
struct tm *tmbuf;
time_t *timep;
time_t offset;
{
static int moffset[] =
{ 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
long s;
long j, d, m, y;
offset += *timep;
tmbuf->tm_isdst = 0; /* Someone else can set this */
j = offset / 86400L + 719469;
s = offset % 86400L;
if (s < 0) {
s += 86400L;
j--;
}
tmbuf->tm_sec = s % 60;
tmbuf->tm_min = (s / 60) % 60;
tmbuf->tm_hour = s / 3600;
tmbuf->tm_wday = (j + 2) % 7;
/*
* Julian date converter. Takes a julian date (the number of days since
* some distant epoch or other), and fills tmbuf.
*/
y = (4L * j - 1L) / 146097L;
j = 4L * j - 1L - 146097L * y;
d = j / 4L;
j = (4L * d + 3L) / 1461L;
d = 4L * d + 3L - 1461L * j;
d = (d + 4L) / 4L;
m = (5L * d - 3L) / 153L;
d = 5L * d - 3 - 153L * m;
d = (d + 5L) / 5L;
y = 100L * y + j;
if (m < 10)
m += 2;
else {
m -= 10;
++y;
}
tmbuf->tm_year = y - 1900;
tmbuf->tm_mon = m;
tmbuf->tm_mday = d;
tmbuf->tm_yday = d + moffset[m];
if (m > 1 && ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0)))
tmbuf->tm_yday++;
}
static struct tm *gmtime(timep)
time_t *timep;
{
static struct tm tmb;
__tm_conv(&tmb, timep, 0L);
return &tmb;
}
#endif