相关文章推荐

一、

size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);

The strftime() function returns the number of characters placed in  the
array  s, not including the terminating null byte, provided the string,
including the terminating null byte, fits.  Otherwise,  it  returns  0,
and  the contents of the array is undefined.

把tm转换为字符串,存于s。如strftime(format_time, 100 - 2, "%F %T", time_ptr);

  • %F     Equivalent to %Y-%m-%d (the ISO 8601 date format). (C99)
  • %T     The time in 24-hour notation (%H:%M:%S). (SU)


strptime -------- 将字符串按时间格式转换。命令行输入的检查会用到

二、transform date and time to broken-down time or ASCII

char *asctime(const struct tm *tm);
char *asctime_r(const struct tm *tm, char *buf);
char *ctime(const time_t *timep);
char *ctime_r(const time_t *timep, char *buf);
struct tm *gmtime(const time_t *timep);
struct tm *gmtime_r(const time_t *timep, struct tm *result);
struct tm *localtime(const time_t *timep);
struct tm *localtime_r(const time_t *timep, struct tm *result);
time_t mktime(struct tm *tm);

asctime(), ctime(), gmtime() and localtime()返回指针指向静态数据,因此不是线程安全的。

线程安全版本为time_r(), ctime_r(), gmtime_r() and localtime_r() are specified by SUSv2, and available since libc 5.2.5.

#include <sys/time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);

  • ftime 已经被淘汰了。
  • 秒级,使用time;
  • 毫秒级,使用gettimeofday;
  • 微秒级,使用lock_gettime,但使用不广泛。

struct timeval tv;
gettimeofday(&tv, NULL);
time_t currentTime = tv.tv_sec;

struct tm CurlocalTime;
localtime_r(&currentTime, &CurlocalTime);

char dateTime[20];
strftime(dateTime, 20, "%Y-%m-%dT%H:%M:%S", CurlocalTime);

$ gem install localtime Localtime 是一个超级简单的 gem,它只在页面上获取时间标签,读取 strftime 属性(如果有),并使用用户的本地时间更新文本。 像这样使用它: <%= localtime DateTime.now %> 想要传递一些格式选项吗? 使用 strftime : <%= localtime DateTime.now, "%Y-%m-%d %H:%M" %> %Y-%m-%d %H:%M是默认值,如果您不指定任何内容,将使用该默认值。 分叉它( ) 创建您的功能分支( gi func main(){ // "2015-06-23 17:57:05", as expected fmt.Println(go_ strftime . Strftime ("%Y-%m-%d %H:%M:%S", time.Now())) 某个业务执行时需要写日志,但调用完日志后(日志中有调用 ftime ),调用处附近的变量值莫名地被修改了。换成C++的std::chrono就没这b问题了。gdb显示问题出在 ftime ()上。用gdb的watch定位到日志上。其次,它会污染内存。 localtime_r 的替代实现“` C++ struct tm * my_ localtime_r (const time_t *srctime,struct tm *tm_time) long int n32_Pass4year,n32_hpery;// 每个月的天数 非闰年 const static char Days[12] = {31, 28, 31, 30, 31, 30 才10k 左右的PV,每日的交互日志就已经爆增到500M 的级别,XML 真是万恶阿!电脑技术002pc网从python字典的key以是列表Python 多线程分析来看,对python字典的key以是列表Python 多线程的结果。为了提高日志处理速度,引入多线程。(如果保持这个趋势,我想Hadoop 的技术储备需要尽快考虑了)脚本原执行时间43秒,引入5个worker 的多线程laungcher...   来源:http://cbqcgq.blog.hexun.com/8892167_d.html      C语言时间函数 [原创 2007-04-16 23:30:50]        C语言的标准库函数包括一系列日期和时间处理函数,它们都在头文件中说明。下面列出了这些函数。在头文件中定义了三种类型:time_t,struct tm和c
 
推荐文章