当前位置:网站首页>FormatDateTime说解[通俗易懂]
FormatDateTime说解[通俗易懂]
2022-07-25 19:59:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
描述
返回一个日期或时间格式的表达式。
语法
FormatDateTime(Date[,NamedFormat])
FormatDateTime函数语法有如下几部分:
部分 | 描述 |
|---|---|
Date | 必需的。要被格式化的日期表达式。 |
NamedFormat | 可选的。数字值,表示日期/时间所使用的格式。如果忽略该值,则使用vbGeneralDate。 |
设置值
NamedFormat参数的设置值如下:
常数 | 值 | 描述 |
|---|---|---|
vbGeneralDate | 0 | 显示日期和/或时间。如果有日期部分,则用短日期格式显示。如果有时间部分,则用长时间格式显示。如果都有,两部分都显示。 |
vbLongDate | 1 | 用计算机区域设置值中指定的长日期格式显示日期。 |
vbShortDate | 2 | 用计算机区域设置值中指定的短日期格式显示日期。 |
vbLongTime | 3 | 用计算机区域设置值中指定的时间格式显示时间。 |
vbShortTime | 4 | 用24小时格式(hh:mm)显示时间。 |
Windows中的时间格式还真不少,什么长日期、短日期,两位年份、四位年份等等,在Delphi中可用FormatDateTime函数输出这些格式,下面介绍它的用法:
function FormatDateTime(const Format: string; DateTime: TDateTime): string;
Format参数是一个格式化字符串。DateTime是时间类型。返回值是一种格式化后的字符串,重点来看Format参数中的指令字符:
c 以短时间格式显示时间,即全部是数字的表示
FormatdateTime(‘c’,now);
输出为:2004-8-7 9:55:40
d 对应于时间中的日期,日期是一位则显示一位,两位则显示两位
FormatdateTime(‘d’,now);
输出可能为1~31
dd 和d的意义一样,但它始终是以两位来显示的
FormatdateTime(‘dd’,now);
输出可能为01~31
ddd 显示的是星期几
FormatdateTime(‘ddd’,now);
输出为: 星期六
dddd 和ddd显示的是一样的。
但上面两个如果在其他国家可能不一样。
ddddd 以短时间格式显示年月日
FormatdateTime(‘ddddd’,now);
输出为:2004-8-7
dddddd 以长时间格式显示年月日
FormatdateTime(‘dddddd’,now);
输出为:2004年8月7日
e/ee/eee/eeee 以相应的位数显示年
FormatdateTime(‘ee’,now);
输出为:04 (表示04年)
m/mm/mmm/mmmm 表示月
FormatdateTime(‘m’,now);
输出为:8
FormatdateTime(‘mm’,now);
输出为 08
FormatdateTime(‘mmm’,now);
输出为 八月
FormatdateTime(‘mmmm’,now);
输出为 八月
和ddd/dddd 一样,在其他国家可能不同
yy/yyyy 表示年
FormatdateTime(‘yy’,now);
输出为 04
FormatdateTime(‘yyyy’,now);
输出为 2004
h/hh,n/nn,s/ss,z/zzz 分别表示小时,分,秒,毫秒
t 以短时间格式显示时间
FormatdateTime(‘t’,now);
输出为 10:17
tt 以长时间格式显示时间
FormatdateTime(‘tt’,now);
输出为10:18:46
ampm 以长时间格式显示上午还是下午
FormatdateTime(‘ttampm’,now);
输出为:10:22:57上午
如果要在Format中加普通的字符串,可以用双引号隔开那些特定义的字符,这样普通字符串中如果含特殊的字符就不会被显示为时间格式啦:
FormatdateTime(‘”today is” c’,now);
输出为:today is 2004-8-7 10:26:58
时间中也可以加”-“或”\”来分开日期:
FormatdateTime(‘”today is” yy-mm-dd’,now);
FormatdateTime(‘”today is” yy\mm\dd’,now);
输出为: today is 04-08-07
也可以用”:”来分开时间
FormatdateTime(‘”today is” hh:nn:ss’,now);
输出为:today is 10:32:23
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/127536.html原文链接:https://javaforall.cn
边栏推荐
- Ml programming skills:
- Digital informatization (enumerate assumptions first, and then see whether the conditions are met) (1089 werewolf kill - simple version)
- JVM(二十三) -- JVM运行时参数
- Prescan quick start to master the special functions of prescan track editing in lecture 18
- [wp]ctfshow-web入门信息搜集
- 各厂商网络虚拟化的优势
- Basic practice of Blue Bridge Cup - shape retrieval of matrix (C language)
- How does tiktok break zero?
- Global configuration and page configuration of wechat applet development
- Rainbow plug-in extension: monitor MySQL based on MySQL exporter
猜你喜欢

Beihang and other "deep learning event extraction" literature review paper, 27 page PDF describes the current trend
![Partial interpretation of yolov7 paper [including my own understanding]](/img/80/95d00565c4ec89a388ae4386801a02.png)
Partial interpretation of yolov7 paper [including my own understanding]

打印数据库返回的查询数据是null,或者是默认值。与数据库返回的值不相符

Global configuration and page configuration of wechat applet development

基于海思3559 高效率的 0延时 0拷贝 qt播放器方案

9.< tag-动态规划和子序列, 子数组>lt.718. 最长重复子数组 + lt.1143. 最长公共子序列

Research and application of servo driver in robot

PreScan快速入门到精通第十八讲之PreScan轨迹编辑的特殊功能

How to get started quickly in software testing

Binarysearch basic binary search
随机推荐
PMP每日一练 | 考试不迷路-7.25
Concept of IP address
tiktok手机网络环境怎么设置?tiktok怎么破播放量?
[CSAPP Practice Problem 2.32] tsub_ok(int x, int y)判断补码减法是否溢出
Split very long line of words into separate lines of max length
Google pixel 6A off screen fingerprint scanner has major security vulnerabilities
PreScan快速入门到精通第十九讲之PreScan执行器配置、轨迹同步及非配多个轨迹
Prescan quick start to master Lesson 19: prescan actuator configuration, track synchronization and non configuration of multiple tracks
Rainbow plug-in extension: monitor MySQL based on MySQL exporter
JVM (XXIII) -- JVM runtime parameters
参与开源社区还有证书拿?
A good way to generate interface documents efficiently
When AI encounters life and health, Huawei cloud builds three bridges for them
CarSim仿真快速入门(十五)—CarSim传感器仿真之ADAS Sensor Objects (1)
[wp]ctfshow-web introductory information collection
10. < tag dynamic programming and subsequence, subarray> lt.53. maximum subarray and + lt.392. Judge subsequence DBC
The use of new promise, async and await in the project, and the practical application of promise.all in the project
Global configuration and page configuration of wechat applet development
wallys//wifi6 wifi5 router IPQ6018 IPQ4019 IPQ4029 802.11ax 802.11ac
Add a subtitle of 3D effect to the container