FormatDateTime 如何得到 英文月份的缩写?

jaffy 2006-08-24 10:39:01
按照定义,我把月份写MMM,本指望得到英文月份的缩写,结果得到中文月份的显示,怎么才能得到英文月份?是不是要设置系统才行.
...全文
2748 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jaffy 2006-08-24
  • 打赏
  • 举报
回复
其实问题不复杂,自己写一个,也没什么.准备结帖了.
jaffy 2006-08-24
  • 打赏
  • 举报
回复
兰色的不对,
unsigned(僵哥)的代码看不懂,能说详细点吗?
僵哥 2006-08-24
  • 打赏
  • 举报
回复
#include <time.h>

struct tm *time_now;
time_t secs_now;
char str[80];

tzset();
time(&secs_now);
time_now = localtime(&secs_now);
strftime(str, 80,
"%A, %b %d 19%y",
time_now);
ShowMessage(str);
BlueDeepOcean 2006-08-24
  • 打赏
  • 举报
回复
应该和系统的区域设置有关。
i_love_pc 2006-08-24
  • 打赏
  • 举报
回复
是不是和安装时候的地域选择有关系,我的cb6也是这种情况,还要自己写了一个转换吗?
BlueDeepOcean 2006-08-24
  • 打赏
  • 举报
回复
上面的5是根据字符串“yyyymmmdd hh:mm:ss”中“m”的起始位置以及个数确定的。
BlueDeepOcean 2006-08-24
  • 打赏
  • 举报
回复
AnsiString as = FormatDateTime("yyyymmmdd hh:mm:ss",Now());
ShowMessage(as.SubString(5,3));
BlueDeepOcean 2006-08-24
  • 打赏
  • 举报
回复
mmm Displays the month as an abbreviation (Jan-Dec) using the strings given by the ShortMonthNames global variable.
僵哥 2006-08-24
  • 打赏
  • 举报
回复
另外可以使用API GetDateFormat来执行转换,但是千万要记住,LanguageID不可以使用当前的,否则在非英文系统下就有可能不是你所想要的.
僵哥 2006-08-24
  • 打赏
  • 举报
回复
unsigned(僵哥)的代码看不懂,能说详细点吗?
====================================
不要光让给说详细解释,其实就是strftime(str表示string,f表示Format),也就是针对时间的格式化,相关的可以按一下F1得到帮助,具体的%(x)代表什么意思,在当中就有:




Format specifier Substitutes

%% Character %
%#% Character %, flag is ignored
%a Abbreviated weekday name
%#a Abbreviated weekday name, flag is ignored
%A Full weekday name
%#A Full weekday name, flag is ignored
%b Abbreviated month name
%#b Abbreviated month name, flag is ignored
%B Full month name
%#B Full month name, flag is ignored
%c Date and time
%#c Long date and time representation, appropriate for current locale. For example: Tuesday, March 14, 1995, 12:41:29
%d Two-digit day of month (01 - 31)

%#d Two-digit day of month, remove leading zeros (if any)
%H Hour of the day, 24 hour day
%#H Hour of the day, 24 hour day, remove leading zeros (if any)
%I Two-digit hour, 12 hour day (01 - 12)
%#I Two-digit hour, 12 hour day, remove leading zeros (if any)
%j Three-digit day of year (001 - 366)
%#j Three-digit day of year, remove leading zeros (if any)
%m Two-digit month as a decimal number (1 - 12)
%#m Two-digit month as a decimal number, remove leading zeros (if any)

%M 2-digit minute (00 - 59)
%#M 2-digit minute, remove leading zeros (if any)
%p AM or PM
%#p AM or PM, flag is ignored
%S Two-digit second (00 - 59)
%#S Two-digit second, remove leading zeros (if any)
%U Two-digit week number where Sunday is the first day of the week (00 - 53)
%#U Two-digit week number where Sunday is the first day of the week, remove leading zeros (if any)
%w Weekday where 0 is Sunday (0 - 6)
%#w Weekday where 0 is Sunday, remove leading zeros (if any)

%W Two-digit week number where Monday is the first day of week the week (00 - 53)
%#W Two-digit week number where Monday is the first day of week the week, remove leading zeros (if any)
%x Date
%#x Long date representation, appropriate to current locale. For example: Tuesday, March 14, 1995
%X Time
%#X Time, flag is ignored
%y Two-digit year without century (00 to 99)
%#y Two-digit year without century, remove leading zeros (if any)
%Y Year with century
%#Y Year with century, remove leading zeros (if any)

%Z, %z Time zone name, or no characters if no time zone
%#Z Time zone name, or no characters if no time zone, flag is ignored

13,874

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧