Chinaunix首页 | 论坛 | 博客
  • 博客访问: 707308
  • 博文数量: 181
  • 博客积分: 2548
  • 博客等级: 少校
  • 技术积分: 1739
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-29 16:36
个人简介

爱咋咋地

文章分类

全部博文(181)

文章存档

2023年(17)

2022年(19)

2021年(3)

2020年(1)

2018年(1)

2017年(1)

2014年(1)

2013年(4)

2012年(11)

2011年(19)

2010年(22)

2009年(71)

2008年(5)

分类: LINUX

2009-11-06 19:24:29

Formatting dates with strftime

strftime is the Standard C library date formatting routine. An date can be formatted with it:

#include 
#include 
#include 
	
char expire_time[32]; /* this date format is of deterministic length */
time_t expire;
int	strflen;

setlocale(LC_TIME, "POSIX");
/* make sure we get a system-independent date */
if( _putenv_s( "TZ", "GMT" ) != 0 )
   printf( "Unable to set TZ\n" );
else
   tzset();
/* actually format it */

strflen = strftime(expire_time, sizeof(expire_time), "%a, %d %b %Y %H:%M:%S +0000", gmtime(&expire));

This example is a (that spec has been superseded by which references for Expires, which points to RFC 1123) expiry time.


Provided with no warranty by

notes: a lot of people don't think this code is quite right... they may be correct. It does compile and run; some of these routines are deprecated. Last modified at time_t 1163178746 (GMT). For email, see and note the differences in time-zones, but RFC 1123 says "should use numeric zones". YMMV

This page is placed in the Public Domain

阅读(7527) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~