Foxtable(狐表)用户栏目专家坐堂 → 格式化日期和时间


  共有3531人关注过本帖树形打印复制链接

主题:格式化日期和时间

帅哥哟,离线,有人找我吗?
lyfxybc
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/5/1 23:00:00 [显示全部帖子]

参考一下:不一定最佳

 先把 2015/4/21 转换为 4/21/2015

Dim s As String = Format(#04/21/2015#,"MM")
'Dim nms() As String = {"1","2","3","4","5","6","7","8","9","10","11","12"} '定义12个月
Dim ics() As String = {"M","F","W","APR","F","S","SE","AP","N","T","J","TW"} '定义12个月对应英文

Dim str As String
   str=ics(s-1)
'Output.Show(str)
Dim s1 As String =Format(#4/21/2015#,"ddMMyyyy")
Dim s2 As String
s2 = s1.Replace(s,str) '将123替换为789
OutPut.Show(s2)

[此贴子已经被作者于2015/5/1 23:04:33编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/5/2 19:41:00 [显示全部帖子]

是否是在excel使用

 回到顶部
帅哥哟,离线,有人找我吗?
lyfxybc
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:六尾狐 帖子:1294 积分:9852 威望:0 精华:0 注册:2012/9/19 21:13:00
  发帖心情 Post By:2015/5/2 20:47:00 [显示全部帖子]

日期列设为字符列,将DataRowAdding事件的代码设置为:

e.DataRow("日期") = Date.Today()

 

在DataColChanged事件中设置如下代码即可: 

Dim y As Integer = Date.Today.Year
Dim m As Integer = Date.Today.Month
Dim d As Integer = Date.Today.day
Dim StartDate As Date
StartDate = New Date(y,m,d)
Dim s As String = Format(StartDate,"MM")
Dim ics() As String = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"} '定义12个月对应英文
Dim str As String
   str=ics(s-1)
Dim ss As String =Format(StartDate,"ddMMyyyy")
ss = ss.Replace(s,str)

e.DataRow("日期") = ss

 

用增加行试一试


[此贴子已经被作者于2015/5/2 20:50:07编辑过]

 回到顶部