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

查看:11
本文介绍了如何以格式打印时间: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;

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

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

对于毫秒部分,看看这个问题.如何使用 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天全站免登陆