七郎's JavaBlog

          草木竹石皆可為劒。至人之用人若鏡,不將不迎,應而不藏,故能勝物而不傷。
          posts - 60, comments - 14, trackbacks - 0, articles - 0

          又一個格式化時間日期函數

          Posted on 2007-04-16 15:36 七郎歸來 閱讀(153) 評論(0)  編輯  收藏
          我們有時候遇到的日期格式可能是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



          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 陆良县| 宝山区| 安龙县| 灵寿县| 百色市| 旬阳县| 邯郸市| 卢龙县| 秦安县| 乡宁县| 青海省| 阆中市| 孟州市| 沈阳市| 凤冈县| 龙海市| 南和县| 饶平县| 南阳市| 建水县| 南城县| 西贡区| 井冈山市| 东乡族自治县| 华蓥市| 吉木萨尔县| 安仁县| 玉田县| 浠水县| 青神县| 乃东县| 吉木萨尔县| 三门县| 上饶县| 麻江县| 阳西县| 平江县| 荥阳市| 临清市| 榆社县| 通渭县|