[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Date/time funktioner



On Thu, 24 May 2001 02:59:29 +0200,
Søren H. Sørensen <sslug@sslug> wrote:

>Lige en velment advarsel. Både "strfrime" og også "localtime" (som godt
>nok bruges på en helt anden måde) giver at året lige nu er 101, og ikke
>bare 1. Jeg måtte droppe strftime for nylig og bruge localtime for at
>kunne rette i årstallet.

Fra den hvide bibel, K&R, Brian og Dennis, eller hvad man nu foretrækker
at kalde den:

...and struct tm holds the components of a calender time:
...
int tm_year;	years since 1900
...

(Så her _skal_ tm_year være 101)

og ved strftime:

%y  year without century (00-99)
%Y  year with century

Jeg prøvede lige med følgende kode:

#include <time.h>
#include <stdio.h>

int main()
{
   char s[81];
   time_t t=time(0);
   strftime(s,80,"%y %Y",localtime(&t));

   printf("%s\n",s);
}

Og den giver "01 2001" som forventet.

-- 
Anders Bo Rasmussen          mailto:sslug@sslug
Frimestervej 42 1.tv         http://www.fuzz.dk
2400 Kbh. NV
Denmark


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *