🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.c
Article #308660

Re: Jak zamienić czas z formatu Unixa na YYYY-MM-DD hh:mm:ss ?

#308660
From: Adam Wysocki
Date: Tue, 14 Jun 2016 21:47
21 lines
1998 bytes
Mateusz Viste <mateusz.viste@localhost> wrote:

> Wrzucasz twój time_t do gmtime() lub localtime(), zależnie od tego co 
> preferujesz otrzymać na wyjściu, a następnie odczytujesz interesujące 
> cię pola z wynikowego struct tm (uwaga: niektóre wartości zaczynają się 
> od 1 - np. dzień miesiąca, a inne od 0 - np. miesiąc czy dzień tygodnia).

Lepiej użyć localtime_r, bo jest reentrant, i strftime, bo można od razu 
zrobić sobie stringa.

time_t t(time(NULL));
tm tm;
localtime(&t, &tm);

char buf[64];
strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &tm);

O tak jakoś bym.

-- 
http://www.chmurka.net/
Technical Details
Message-ID: <hTcksis0IdlvNv8%gof@news.chmurka.net>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.chmurka.net!.POSTED.172.24.44.4!not-for-mail
References: <njdvd9$2uv$2@node1.news.atman.pl> <575bc5af$0$5442$426a34cc@news.free.fr>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!news.chmurka.net!.POSTED.172.24.44.4!not-for-mail
From: gof@somewhere.invalid (Adam Wysocki)
Newsgroups: pl.comp.lang.c
Subject: Re: Jak zamienić czas z formatu Unixa na YYYY-MM-DD
 hh:mm:ss ?
Date: Tue, 14 Jun 2016 21:47:30 +0000 (UTC)
Organization: news.chmurka.net
Message-ID: <hTcksis0IdlvNv8%gof@news.chmurka.net>
References: <njdvd9$2uv$2@node1.news.atman.pl> <575bc5af$0$5442$426a34cc@news.free.fr>
Mime-Version: 1.0
Injection-Date: Tue, 14 Jun 2016 21:47:30 +0000 (UTC)
Injection-Info: news.chmurka.net; posting-account="gof"; posting-host="172.24.44.4"; logging-data="18964"; mail-complaints-to="abuse-news.(at).chmurka.net"
User-Agent: tin/2.3.3-20160327 ("Kinloch") (UNIX) (Linux/3.16.0-4-amd64 (x86_64))
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/simple; d=chmurka.net; s=news; t=1465940896; bh=4FUUTZusZdEQ1Aa5lUXpCjOmUqk=; h=From:Subject:Newsgroups:References:Message-ID:Cancel-Lock:  User-Agent:MIME-Version:Content-Type:Content-Transfer-Encoding; b=dn/9BSgl/4C74uS3lEmW8484Plttrs9KwbqU5/DRvtH6Oi40WcFhYViCOdRvi+yJv  A5KKfQCz+gZjrNZtSLtbT3a3mcxd0VLzlVhV5qiVRpMPODF1d7GW6OabC2AFjzPHNm  OrviTxTAhqe/yHXUDZVEflYjDxk3LioeI0i11qow=11qow=
Cancel-Lock: sha1:IwkJVToaU7UeAgjmObCpRTx8mwc=
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit