Author Topic: ParseDate 強化版本  (Read 3703 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
ParseDate 強化版本
« on: August 23, 2011, 07:30:19 PM »
Code: [Select]
Function czParseDateTime(tmpString as string, byref tmpDateTime as date) As boolean
  dim tmpResult as boolean=false
  dim tmpSeparator as string="/"
  dim intX as integer
  dim tmpYear as integer
  dim tmpMonth as integer
  dim tmpDay as integer
 
  if len(tmpString) >0 then
   
    for intx=1 to len(tmpString)
      select case mid(tmpString,intx,1)
      case "/"
        tmpSeparator="/"
        exit for
       
      case "-"
        tmpSeparator="-"
        exit for
       
      case else
       
      end select
    next
   
    tmpYear=val(NthField(tmpString,tmpSeparator,1))
    tmpMonth=val(NthField(tmpString,tmpSeparator,2))
    tmpDay=val(NthField(tmpString,tmpSeparator,3))
   
    if tmpyear>0 and tmpMonth >0 and tmpDay >0 then
      tmpDateTime=new Date
      tmpDateTime.Year=tmpyear
      tmpDateTime.Month=tmpMonth
      tmpDateTime.Day=tmpday
      tmpResult=true
    end if
   
   
    if tmpResult=true then
      dim tmpTime as string = NthField(tmpString ," ",2)
      if len(tmptime) >0 then
        dim tmpHour as integer = val(NthField(tmptime,":",1))
        dim tmpMinute as integer = val(NthField(tmptime,":",2))
        dim tmpSecond as integer = val(NthField(tmptime,":",3))
       
        tmpDateTime.Hour=tmpHour
        tmpDateTime.Minute=tmpMinute
        tmpDateTime.Second=tmpSecond
      end if
     
    end if
       
  end if
 
  return tmpResult
 
End Function
« Last Edit: October 23, 2011, 01:44:41 AM by Roy Chan »