如何将时间转换为军用时间? [英] How do I convert the time to military time?

查看:54
本文介绍了如何将时间转换为军用时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从文件中获取输入.时间可能是军用时间或标准时间(上午/下午)

I am getting input from a file. The time maybe military or standard (AM/PM)

我需要将时间转换为军事时间.

I need to convert the time to military.

以下是 CSV 文件中时间的一些示例

Here are some examples of the time in the CSV file

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

推荐答案


首先,我不确定我是否正确理解了这个问题.可能是这样的:


Firstly I'm not sure whether I understood the question correctly. Could be like this:

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

这篇关于如何将时间转换为军用时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆