var
s: string;
begin
//FormatDateTime 的参数1是 String 格式指令, 参数2是 TDateTime 类型的时间
s := FormatDateTime('c', Now); {返回: 2007-12-18 23:56:05}
{指令 c 表示用短格式显示日期与时间}
s := FormatDateTime('d', Now); {返回: 19}
s := FormatDateTime('d', StrToDateTime('2008-1-1')); {返回: 1}
{d 表示日期}
s := FormatDateTime('dd', Now); {返回: 19}
s := FormatDateTime('dd', StrToDateTime('2008-1-1')); {返回: 01}
{dd 表示双位日期}
s := FormatDateTime('ddd', Now); {返回: 星期三}
s := FormatDateTime('dddd', Now); {返回: 星期三}
{ddd 与 dddd 表示星期; 可能对不同的语种会有区别}
s := FormatDateTime('ddddd', Now); {返回: 2007-12-19}
{ddddd 五个 d 表示短格式日期}
s := FormatDateTime('dddddd', Now); {返回: 2007年12月19日}
{dddddd 六个 d 表示长格式日期}
s := FormatDateTime('e', Now); {返回: 7}
{e 表示年, 1位}
s := FormatDateTime('ee', Now); {返回: 07}
{ee 表示年, 2位}
s := FormatDateTime('eee', Now); {返回: 2007}
s := FormatDateTime('eeee', Now); {返回: 2007}
{eee 与 eeee 返回4位数年}
s := FormatDateTime('m', Now); {返回: 12}
{m 表示月, 1位}
s := FormatDateTime('mm', StrToDateTime('2008-1-1')); {返回: 01}
{mm 表示月, 2位}
s := FormatDateTime('mmm', Now); {返回: 十二月}
s := FormatDateTime('mmmm', Now); {返回: 十二月}
{mmm 与 mmmm 表示长格式月}
s := FormatDateTime('y', Now); {返回: 07}
s := FormatDateTime('yy', Now); {返回: 07}
s := FormatDateTime('yyy', Now); {返回: 2007}
s := FormatDateTime('yyyy', Now); {返回: 2007}
{y yy yyy yyyy 表示年; 和 e 略有不同}
s := FormatDateTime('t', Now); {返回: 0:21}
s := FormatDateTime('tt', Now); {返回: 0:22:13}
{t tt 表示时间}
s := FormatDateTime('ampm', Now); {返回: 上午}
s := FormatDateTime('tampm', Now); {返回: 0:24 上午}
{ampm 表示上午、下午}
s := FormatDateTime('h', StrToDateTime('2007-12-30 9:58:06')); {返回: 9}
s := FormatDateTime('hh', StrToDateTime('2007-12-30 9:58:06')); {返回: 09}
{h hh 表示时}
s := FormatDateTime('n', StrToDateTime('2007-12-30 9:58:06')); {返回: 58}
s := FormatDateTime('nn', StrToDateTime('2007-12-30 9:58:06')); {返回: 58}
{n nn 表示分}
s := FormatDateTime('s', StrToDateTime('2007-12-30 9:58:06')); {返回: 6}
s := FormatDateTime('ss', StrToDateTime('2007-12-30 9:58:06')); {返回: 06}
{s ss 表示秒}
s := FormatDateTime('z', Now); {返回: 24}
s := FormatDateTime('zz', Now); {返回: 524}
s := FormatDateTime('zzz', Now); {返回: 524}
{z zz zzz 表示毫秒}
s := FormatDateTime('yy\mm\dd', Now); {返回: 07\12\19}
s := FormatDateTime('yy/mm/dd', Now); {返回: 07-12-19}
s := FormatDateTime('yy-mm-dd', Now); {返回: 07-12-19}
s := FormatDateTime('yy*mm*dd', Now); {返回: 07*12*19}
{使用分隔符, - 是默认的, / 是与 - 等效的, 假如我非要用 / 显示呢?}
s := FormatDateTime('yy"/"mm"/"dd', Now); {返回: 07/12/19}
s := FormatDateTime('"当前时间是: "yyyy-m-d h:n:s:zz', Now);
{返回: 当前时间是: 2007-12-19 0:47:16:576}
{混入的字符串要包含在双引号中}
ShowMessage(s);
end;
top_print_time := FormatDateTime('yyyy-mm-dd hh:mm:ss', Now);
真的是很强大!!!!
本文来自博客园,作者:del88,转载请注明原文链接:https://www.cnblogs.com/del88/archive/2011/11/21/2256821.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人