我们有时候遇到的日期格式可能是2004-1-12 ,系统自动将月份中的0去掉了,但是有时候我们需要完整的日期格式 ,如:2004-01-12 那么怎么办呢?下面的几个函数可以轻松搞定。
'将一个一位的数字前面加零
function FillZero(str)
ttt=str
if len(str)=1 then
ttt="0" & str
end if
FillZero=ttt
end function
'转化日期,将 一位补上零 2003-1-2 --> 2003-01-02
function ConvertDate(tDate)
ttt=tDate
if isdate(tDate) then
ttt=year(tDate) & "-" & FillZero(month(tDate)) & "-" & FillZero(day(tDate))
end if
ConvertDate=ttt
end function
'输入一个日期时间串,转换成年四位,其他两位的新的日期时间串
function ConvertDateTime(tDateTime)
ttt=tDateTime
if isdate(tDateTime) then
ttt=year(tDateTime) & "-" & FillZero(month(tDateTime)) & "-" & FillZero(day(tDateTime)) & " " & FillZero(cstr(hour(tDateTime))) & ":" & FillZero(cstr(minute(tDateTime))) & ":" & FillZero(cstr(second(tDateTime)))
end if
ConvertDateTime=ttt
end function
分享到:
相关推荐
日期格式化函数
Sql Server 中一个非常强大的日期格式化函数
各种格式化日期函数,可以控制查询结果的日期显示格式,所有的格式都包含其中!
javascript的TRIM函数和日期时间格式化函数 如 var d = new Date().format('yyyy-MM-dd hh:mm:ss');
keil插件包(格式化代码 文件注释 函数注释 当前日期 当前时间) Astyle插件包,下载下来解压后将文件夹放在Keil文件里面。
Select CONVERT(varchar(100), GETDATE(), 22): 05/16/06 10:57:47 AM Select CONVERT(varchar(100), GETDATE(), 23): 2006-05-16
VB 中 Format 格式化日期时间、数字函数功能详解,详情包含有: 数字类型的格式化 日期类型的格式化 文本类型的格式化 强制使用中文格式的日期时间 总结:这是一份不可多得的珍贵珍藏版资源!!!
pb 日期函数
SQL\日期、數字格式化函数大全
keil插件包,导入这些插件实现(格式化代码 文件注释 函数注释 当前日期 当前时间)等功能,更加方便嵌入式开发。使用教程:https://blog.csdn.net/qq_44078824/article/details/109349611
日期输出格式函数,具体内容自己研究。日期输出格式函数,具体内容自己研究。
Gbase 8s内置函数之日期函数
很多时候,我们可以利用JavaScript中Date对象的内置方法来格式化,如: 代码如下:var d = new Date();console.log(d); // 输出:Mon Nov 04 2013 21:50:33 GMT+0800 (中国标准时间)console.log(d.toDateString()); /...
PB日期转换 PB格式转换 日期、时间函数 打印函数
Freemarker_内置函数_数字、字符串、日期格式化.txt
js中格式化日期时间型数据函数代码.docx
1 取值后格式化 {0:d}小型:如2005-5-6 {0:D}大型:如2005年5月6日 {0:f}完整型 2 当前时间获取 DateTime.Now.ToShortDateString 3 取值中格式化 SQL Server里面可能经常会用到的日期格式转换方法: sql server使用...