__DATE__宏的不同格式 [英] Different format of __DATE__ macro

查看:188
本文介绍了__DATE__宏的不同格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C有一个预定义的宏__DATE__,该宏显示了已编译的源文件的日期.
日期以"mm dd yyyy" 的格式显示.

C has a predefined macro __DATE__, that shows the date of the compiled source file .
The date is displayed in the format "Mmm dd yyyy" .

有什么办法可以使用宏格式化该日期?
"yyyy Mmm dd" .

Is there any way to be formatted this date, using macros ?
In this format "yyyy Mmm dd".

而不是:

2013年7月19日

Jul 19 2013

应该是:

2013年7月19日

2013 Jul 19

推荐答案

在C语言中,您可以使用一个宏来动态生成具有您想要的顺序的复合文字,例如

In C you could have a macro that generates a compound literal on the fly that has the order that you like, something like

#define FDATE (char const[]){ __DATE__[7], __DATE__[8], ..., ' ', ... , '\0' }

在所有重要的地方,您的优化器都应该能够有效地处理此问题.

in all places where it matters your optimizer should be able to handle this efficiently.

这篇关于__DATE__宏的不同格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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