2011-08-16 83 views
1

我從文件獲取輸入。時間可能是軍事或標準(AM/PM)如何將時間轉換爲軍事時間?

我需要將時間轉換爲軍事。

以下是文件

2011-08-16, 2:28:00 PM, 15:28 
2011-08-16, 1:21:00 PM, 13:28 
2011-08-16, 2:13:00 PM, 16:28 

回答

1


首先我不知道我是否正確地理解問題。 可能是這樣的:

Option Explicit 

Const SOURCE_PATH = "C:\source.csv" 
Const DEST_PATH = "C:\destination.csv" 
Dim oReg, oFso 

Set oReg = New RegExp 
oReg.IgnoreCase = True 
oReg.Global = True 
oReg.Pattern = "\b((1[0-2]|[1-9]):[0-5][0-9]:[0-5][0-9] [AP]M)\b" 

Function cb_MilTime(a, b, c, d, e) 
    cb_MilTime = FormatDateTime(CDate(b), 4) 
    'cb_MilTime = Replace(cb_MilTime, ":", "") 'need seperator? 
End Function 

Set oFso = CreateObject("Scripting.FileSystemObject") 

If oFso.FileExists(SOURCE_PATH) Then 
    oFso.OpenTextFile(DEST_PATH, 2, True).Write(oReg.Replace(_ 
    oFso.OpenTextFile(SOURCE_PATH).ReadAll(), GetRef("cb_MilTime"))) 
Else 
    Err.Raise 8, "Source path does not exists" 
End If 

WScript.Echo "File Saved to "& DEST_PATH 

Set oFso = Nothing 
Set oReg = Nothing 
0

像這樣的東西應該工作在CSV時的一些例子:

Const militaryTimeFormat As String = "HH:mm" 

' convert to a string in military time 
Dim input As String = DateTime.Now.ToString(militaryTimeFormat) 

' convert from a string in military time 
Dim time As DateTime = DateTime.ParseExact(input, militaryTimeFormat, Nothing) 
+0

DateTime是未知對象 –

+0

Try System.DateTime – adritha84

相關問題