如何打印时间格式:2009-08-10 18:17:54.811 [英] How to print time in format: 2009‐08‐10 18:17:54.811

查看:156
本文介绍了如何打印时间格式:2009-08-10 18:17:54.811的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是格式打印出来的时间用C的最佳方法 2009-08-10 18:17:54.811

What's the best method to print out time in C in the format 2009‐08‐10 
18:17:54.811?

推荐答案

使用的strftime()

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

int main()
{
    time_t timer;
    char buffer[26];
    struct tm* tm_info;

    time(&timer);
    tm_info = localtime(&timer);

    strftime(buffer, 26, "%Y:%m:%d %H:%M:%S", tm_info);
    puts(buffer);

    return 0;
}

有关毫秒的部分,看看这个问题。 <一href=\"http://stackoverflow.com/questions/361363/how-to-measure-time-in-milliseconds-using-ansi-c\">How衡量使用ANSI C毫秒的时间?

For milliseconds part, have a look at this question. How to measure time in milliseconds using ANSI C?

这篇关于如何打印时间格式:2009-08-10 18:17:54.811的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆