Date representation as YY/DDD or YYYY/DDD

Wojciech Puchar wojtek at wojtek.tensor.gdynia.pl
Wed Jun 3 21:13:09 UTC 2009


> as 2009-01-01 would be 09/001, 2009-02-01 would be 2009/032.
>
> I've read "man date" and "man strftime", and it didn't look
> like this is already built in.
>
> What am I missing?
>
> If it's not invented yet, I'll do this on my own, but maybe
> I don't need to re-invent the wheel. :-)
>
#include <stdio.h>
#include <time.h>
main(int argc,char **argv) {
  time_t tmp1=time(0);
  struct tm tmp2;
  localtime_r(&tmp1,&tmp2);
  if(argc>1)
   printf("%02d",(tmp2.tm_year/100)+19);
  printf("%02d/%03d\n",tmp2.tm_year%100,tmp2.tm_yday+1);
  return 0;
};



started with no arguments gives YY/DDD, with any argument - YYYY/DDD



More information about the freebsd-questions mailing list