timeValue

時刻を表す文字列をシリアル値に変換します。結果は、0〜0.999988425925926の範囲内の値を取ります。

引数に日付が含まれる場合日付は無視され、時刻情報のみ変換されます。

構文
timeValue( str )
引数
str
時刻文字列。hh:nn:ss AM/PM、hh:nn:ss、hh:nn AM/PM、hh:nn、h AM/PM
戻値
シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59

プログラム

//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn:ss、hh:nn AM/PM、hh:nn、h AM/PM 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	Pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(3), "AM|am"), 0, 12))/ 24 + .SubMatches(1) / 1440 + .SubMatches(2) / 86400
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(2), "AM|am"), 0, 12)) / 24 + .SubMatches(1) / 1440
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)) / 24
			ENDWITH
	SELEND
	RESULT = time
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Execute(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Test(str)
FEND

プログラム実行例

Windowsの稼働時間を取得

HASHTBL INFO

DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
FID = FOPEN(filename, F_READ OR F_WRITE)
FPUT(FID, DOSCMD("systeminfo /FO CSV"))
FCLOSE(FID)

FID = FOPEN(filename, F_READ OR F_WRITE)
FOR col = 0 TO 33
	INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)
NEXT
FCLOSE(FID)

FSO.DeleteFile(filename)

DIM startupTime = INFO["システム起動時間"]
date1 = dateValue(startupTime) + timeValue(startupTime)
date2 = uwscToSerial(GETTIME())
PRINT INT(date2 - date1) + ":" + text(date2 - date1, "hh:mm:ss")

//////////////////////////////////////////////////
// 【引数】
//   callback : 配列の各要素に適用するコールバック関数 
//   array : コールバック関数を適用する配列 
// 【戻値】
//   callback関数を適用した後、 適用後の要素を含む配列 
//////////////////////////////////////////////////
PROCEDURE arrayMap(callback, var array[])
	DIM tmp[RESIZE(array)]
	DIM n = 0
	FOR %val% IN array
		tmp[n] = EVAL(callback)
		n = n + 1
	NEXT
	RESIZE(array, RESIZE(tmp))
	FOR n = 0 TO RESIZE(tmp)
		array[n] = tmp[n]
	NEXT
FEND

//////////////////////////////////////////////////
// 【引数】
//   needle : 検索する値 
//   haystack : 配列 
// 【戻値】
//   needleが見つかった場合に配列のキー 
//////////////////////////////////////////////////
FUNCTION arraySearch(needle, haystack[])
	DIM i = 0
	FOR item IN haystack
		IFB item = needle THEN
			RESULT = i
			EXIT
		ENDIF
		i = i + 1
	NEXT
FEND

//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、m︰月、d︰日) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた日数を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
	DIM y1, y2, m1, m2, d1, d2, d
	SELECT interval
		CASE "yyyy"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			GETTIME(0, date2)
			y2 = G_TIME_YY
			d = y2 - y1
		CASE "m"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			m1 = G_TIME_MM
			GETTIME(0, date2)
			y2 = G_TIME_YY
			m2 = G_TIME_MM
			d = (y2 - y1) * 12 + m2 - m1
		CASE "d"
			d1 = GETTIME(0, date1)
			d2 = GETTIME(0, date2)
			d = (d2 - d1) / 86400
	SELEND
	RESULT = d
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 日付文字列。yyyy/mm/dd、dd/mm/yyyy、yyyy年mm月dd日、yyyy年mm月、ge年mm月dd日、mm/dd、mm月dd日 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION dateValue(str)
	HASHTBL Pattern
	Pattern["year"] = "(190[0-9]|19[1-9][0-9]|[2-9][0-9]{3})"
	Pattern["month"] = "(1[0-2]|0?[1-9]|Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)"
	Pattern["day"] = "([1-2][0-9]|3[0-1]|0?[1-9])"
	
	SELECT TRUE
		CASE reTest(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
			Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"] + "/" + Pattern["day"])
			WITH Matches.Item(0)
				date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
			ENDWITH
		CASE reTest(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
			Matches = reExecute(str, Pattern["day"] + "/" + Pattern["month"] + "/" + Pattern["year"])
			WITH Matches.Item(0)
				IFB reTest(.SubMatches(1), "Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Ap(?:ril)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?")
					DIM array[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
					IF LENGTH(.SubMatches(1)) = 3 THEN arrayMap("COPY(%val%, 1, 3)", array)
					m = arraySearch(.SubMatches(1), array) + 1
				ELSE
					m = .SubMatches(1)
				ENDIF
				date = .SubMatches(2) + "/" + text(m, "00") + "/" + .SubMatches(0)
			ENDWITH
		CASE reTest(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
			Matches = reExecute(str, Pattern["year"] + "年" + Pattern["month"] + "月" + Pattern["day"] + "日")
			WITH Matches.Item(0)
				date = .SubMatches(0) + "/" + text(VAL(.SubMatches(1)), "00") + "/" + text(VAL(.SubMatches(2)), "00")
			ENDWITH
		CASE reTest(str, Pattern["year"] + "/" + Pattern["month"])
			Matches = reExecute(str, Pattern["year"] + "/" + Pattern["month"])
			WITH Matches.Item(0)
				date = .SubMatches(0) + "/" + .SubMatches(1) + "/01"
			ENDWITH
		CASE reTest(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
			Matches = reExecute(str, "([MTSHR])(\d+)/" + Pattern["month"] + "/" + Pattern["day"])
			WITH Matches.Item(0)
				y = VAL(.SubMatches(1))
				SELECT .SubMatches(0)
					CASE "M"; y = y + 1867
					CASE "T"; y = y + 1911
					CASE "S"; y = y + 1925
					CASE "H"; y = y + 1988
					CASE "R"; y = y + 2018
				SELEND
				date = y + "/" + .SubMatches(2) + "/" + .SubMatches(3)
			ENDWITH
		CASE reTest(str, Pattern["month"] + "/" + Pattern["day"])
			Matches = reExecute(str, Pattern["month"] + "/" + Pattern["day"])
			GETTIME()
			WITH Matches.Item(0)
				date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
			ENDWITH
		CASE reTest(str, Pattern["month"] + "月" + Pattern["day"] + "日")
			Matches = reExecute(str, Pattern["month"] + "月" + Pattern["day"] + "日")
			GETTIME()
			WITH Matches.Item(0)
				date = G_TIME_YY4 + "/" + text(VAL(.SubMatches(0)), "00") + "/" + text(VAL(.SubMatches(1)), "00")
			ENDWITH
	SELEND
	RESULT = uwscToSerial(GETTIME(0, date))
FEND

//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
	DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
	DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
	DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
	match = reExecute(format, "(a|d)+")
	type = match.Item(0).Value
	RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND

//////////////////////////////////////////////////
// 【引数】
//   シリアル値 : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
	RESULT = REPLACE(FORMAT(INT(serial * 24), 2), " ", "0")
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Execute(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Replace(str1, str2)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Test(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
	DIM res = ""
	FOR n = 1 TO multiplier
		res = res + inputs
	NEXT
	RESULT = res
FEND

//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
	HASHTBL startDate
	startDate["明治"] = "1868/01/25"
	startDate["大正"] = "1912/07/30"
	startDate["昭和"] = "1926/12/25"
	startDate["平成"] = "1989/01/08"
	startDate["令和"] = "2019/05/01"
	
	DIM baseDate = "1899/12/30"
	
	SELECT TRUE
		CASE reTest(format, "\[h+\]")
			Matches = reExecute(format, "\[(h+)\]")
			DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "^h+$")
			Matches = reExecute(format, "^(h+)$")
			hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "\[m+\]")
			Matches = reExecute(format, "\[(m+)\]")
			RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE format = "m"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_MM, "0")
		CASE format = "mm"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_MM2
		CASE format = "n"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN
		CASE format = "nn"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN2
		CASE format = "s"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_SS, "0")
		CASE format = "ss"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_SS2
		CASE format = "yyyy"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_YY4
		CASE format = "yy"
			GETTIME(serial, baseDate)
			RESULT = COPY(G_TIME_YY4, 3, 2)
		CASE format = "e"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 2018
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1988
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1925
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1911
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1867
			SELEND
		CASE format = "ee"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 2018, "00")
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1988, "00")
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1925, "00")
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1911, "00")
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1867, "00")
			SELEND
		CASE format = "g"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
			SELEND
		CASE format = "gg"
			RESULT = COPY(text(serial, "ggg"), 1, 1)
		CASE format = "ggg"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
			SELEND
		CASE format = "mmmmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 1)
		CASE format = "mmmm"
			DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
			RESULT = month[text(serial, "m") - 1]
		CASE format = "mmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 3)
		CASE format = "dd"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD2, "00")
		CASE format = "d"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD, "0")
		CASE reTest(format, "^[ad]{3,4}$")
			Matches = reExecute(format, "([ad]{3,4})")
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
		CASE reTest(format, "(0+\.?0+)?%")
			Matches = reExecute(format, "(0+\.?0+)?%")
			RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
		CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
			Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
			DIM value = VAL(Matches.Item(0).SubMatches(0))
			DIM sss = text(serial, Matches.Item(0).SubMatches(1))
			Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
			DIM res = ""
			FOR m = 0 TO Matches.Count - 1
				serial = Matches.Item(m).SubMatches(1)
				SELECT value
					CASE 1, 2
						DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
										"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
						DIM a[][3] = "", "十", "百", "千", + _
										"", "拾", "百", "阡"
						DIM b[][3] = "", "万", "億", "兆", + _
										"", "萬", "億", "兆"
						DIM r = ""
						DIM j = 0
						type = value - 1
						REPEAT
							DIM str = ""
							DIM n4 = serial MOD 10000
							FOR i = LENGTH(n4) TO 1 STEP -1
								s = COPY(n4, i, 1)
								IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
									str = IIF(s, a[type][LENGTH(n4)-i], "") + str
								ELSE	
									str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
								ENDIF
							NEXT
							IF str <> "" THEN r = str + b[type][j] + r
							j = j + 1
							serial = INT(serial / 10000)
						UNTIL serial = 0
						res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
					CASE 3
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
					CASE 4
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
				SELEND
			NEXT
			RESULT = res
		CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
			ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
			hour12 = TRUE
			res = ""
			WITH Matches.Item(0)
				res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
			ENDWITH
			RESULT = res
		CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			FOR n = 0 TO Matches.Count - 1
				IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
			NEXT
			FOR n = 0 TO Matches.Count - 1
				WITH Matches.Item(n)
					res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
				ENDWITH
			NEXT
			RESULT = res
		CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
			Matches = reExecute(format, "(0+)\.?(0+)?")
			len1 = LENGTH(Matches.Item(0).SubMatches(0))
			len2 = LENGTH(Matches.Item(0).SubMatches(1))
			DIM arr[] = LENGTH(INT(serial)), len1
			IFB POS(".", format) THEN
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
			ELSE
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
			ENDIF
	SELEND
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn:ss、hh:nn AM/PM、hh:nn、h AM/PM 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	Pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(3), "AM|am"), 0, 12))/ 24 + .SubMatches(1) / 1440 + .SubMatches(2) / 86400
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(2), "AM|am"), 0, 12)) / 24 + .SubMatches(1) / 1440
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)) / 24
			ENDWITH
	SELEND
	RESULT = time
FEND

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND

//////////////////////////////////////////////////
// 【引数】
//   path : ファイルのパス 
// 【戻値】
//   重複しないファイル名 
//////////////////////////////////////////////////
FUNCTION uniqueFilename(path)
	DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
	IFB FSO.FileExists(path) THEN
		DIM fol = FSO.GetParentFolderName(path)
		DIM filename = FSO.GetBaseName(path)
		DIM extension = FSO.GetExtensionName(path)
		DIM i = 2
		WHILE FSO.FileExists(FSO.BuildPath(fol, filename + " (" + i + ")." + extension))
			i = i + 1
		WEND
		RESULT = FSO.BuildPath(fol, filename + " (" + i + ")." + extension)
	ELSE
		RESULT = path
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   uwscTime : UWSC時間 
// 【戻値】
//   シリアル値 
//////////////////////////////////////////////////
FUNCTION uwscToSerial(uwscTime)
	uwscDate = uwscTime / 86400
	RESULT = 36526 + uwscDate
FEND
  1. CREATEOLEOBJ
  2. FSO.BuildPath
  3. FOPEN
  4. FPUT
  5. DOSCMD
  6. FCLOSE
  7. FGET
  8. FSO.DeleteFile
  9. dateValue
  10. timeValue
  11. uwscToSerial
  12. text
結果
0:08:16:46
解説
  1. 1行目
    HASHTBL INFO
    
    連想配列INFOを宣言します。
  2. 3行目
    DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")
    
    FileSystemObjectオブジェクトを作成します。
  3. 5行目
    DIM filename = uniqueFilename(FSO.BuildPath(GET_CUR_DIR, "SYSTEMINFO.csv"))
    
    カレントディレクトリに「SYSTEMINFO.csv」というファイル名でCSVファイルを作成する。
  4. 6行目
    FID = FOPEN(filename, F_READ OR F_WRITE)
    
    「SYSTEMINFO.csv」を読み込み/書き込みモードで開く。
  5. 7行目
    FPUT(FID, DOSCMD("systeminfo /FO CSV"))
    
    コマンドプロンプトで「systeminfo /FO CSV」を実行し、その結果をファイルに書き込む。
  6. 8行目
    FCLOSE(FID)
    
    CSVファイルを閉じる。
  7. 10行目
    FID = FOPEN(filename, F_READ OR F_WRITE)
    
    「SYSTEMINFO.csv」を読み込み/書き込みモードで開く。
  8. 11-13行目
    FOR col = 0 TO 33
    	INFO[FGET(FID, 1, col)] = FGET(FID, 2, col)
    NEXT
    
    1行目に項目、2行目に値が書かれているので、INFO[項目]に値を格納する。
  9. 14行目
    FCLOSE(FID)
    
    CSVファイルを閉じる。
  10. 16行目
    FSO.DeleteFile(filename)
    
    CSVファイルを削除する。
  11. 18行目
    DIM startupTime = INFO["システム起動時間"]
    
    「システム起動時間」をstartupに代入する。
  12. 19行目
    date1 = dateValue(startupTime) + timeValue(startupTime)
    
    時間を小数表記にする。
  13. 20行目
    date2 = uwscToSerial(GETTIME())
    
    UWSC時間をシリアル時間に変換する。
  14. 21行目
    PRINT INT(date2 - date1) + ":" + text(date2 - date1, "hh:mm:ss")
    小数表記から時間表記にする。

時刻文字列をシリアル値に変換

DIM array[] = "0:00:00", "23:59:59", "1 AM", "11 PM", "13:50:25", + _
				"12:56", "2021/06/01 12:52:12", "2021/06/01 01:58 AM"

FOR item IN array
	PRINT timeValue(item)
NEXT

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Execute(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Test(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn:ss、hh:nn AM/PM、hh:nn、h AM/PM 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	Pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(3), "AM|am"), 0, 12))/ 24 + .SubMatches(1) / 1440 + .SubMatches(2) / 86400
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(2), "AM|am"), 0, 12)) / 24 + .SubMatches(1) / 1440
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)) / 24
			ENDWITH
	SELEND
	RESULT = time
FEND
  1. timeValue
結果
0
0.999988425925926
0.0416666666666667
0.958333333333333
0.576678240740741
0.538888888888889
0.53625
0.0819444444444444

指定したフォルダの動画の合計時間を求める

DIM Shell = CREATEOLEOBJ("Shell.Application")
DIM Folder = Shell.NameSpace("D:\Videos\")
DIM FolderItems = Folder.Items
DIM serial

HASHTBL iColumn

FOR n = 0 TO 350
	iColumn[Folder.GetDetailsOf(EMPTYPARAM, n)] = n
NEXT

FOR n = 0 TO FolderItems.Count - 1
	WITH Folder
		DIM FolderItem = .Items.Item(n)
		extension = .GetDetailsOf(FolderItem, iColumn["ファイル拡張子"])
		IFB FolderItem.IsFolder = FALSE THEN
			serial = serial + timeValue(.GetDetailsOf(FolderItem, iColumn["長さ"]))
		ENDIF
	ENDWITH
NEXT

PRINT text(serial, "hh:mm:ss")

//////////////////////////////////////////////////
// 【引数】
//   interval : 時間単位(yyyy︰年、m︰月、d︰日) 
//   date1 : 日時1 
//   date2 : 日時2 
// 【戻値】
//   date2からdate1を引いた日数を求めます。 
//////////////////////////////////////////////////
FUNCTION dateDiff(interval, date1, date2)
	DIM y1, y2, m1, m2, d1, d2, d
	SELECT interval
		CASE "yyyy"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			GETTIME(0, date2)
			y2 = G_TIME_YY
			d = y2 - y1
		CASE "m"
			GETTIME(0, date1)
			y1 = G_TIME_YY
			m1 = G_TIME_MM
			GETTIME(0, date2)
			y2 = G_TIME_YY
			m2 = G_TIME_MM
			d = (y2 - y1) * 12 + m2 - m1
		CASE "d"
			d1 = GETTIME(0, date1)
			d2 = GETTIME(0, date2)
			d = (d2 - d1) / 86400
	SELEND
	RESULT = d
FEND

//////////////////////////////////////////////////
// 【引数】
//   数値 : GETTIMEで取得した曜日の番号(G_TIME_WW=0:日曜….6:土曜) 
//   フォーマット : 以下のアルファベットは数値で指定した対応する曜日に置き換えられます。(aaa : 日〜土、aaaa : 日曜日〜土曜日、ddd : Sun〜Sat、dddd : Sunday〜Saturday) 
// 【戻値】
//   数値をフォーマットした文字列を返します。 
//////////////////////////////////////////////////
FUNCTION getWeekdayName(num, format = "aaa")
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	DIM aaa[] = "日", "月", "火", "水", "木", "金", "土";
	DIM aaaa[] = "日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日";
	DIM ddd[] = "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat";
	DIM dddd[] = "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday";
	match = reExecute(format, "(a|d)+")
	type = match.Item(0).Value
	RESULT = reReplace(format, EVAL(type + "[" + num + "]"), type)
FEND

//////////////////////////////////////////////////
// 【引数】
//   シリアル値 : 時間を表すシリアル値を指定 
// 【戻値】
//   例)0…00、0.5…12、1.0…24 
//////////////////////////////////////////////////
FUNCTION Hour(serial)
	RESULT = REPLACE(FORMAT(INT(serial * 24), 2), " ", "0")
FEND

//////////////////////////////////////////////////
// 【引数】
//   expr : 評価する式 
//   truepart : 評価した式がTrueのときに返す値 
//   falsepart : 評価した式がFalseのときに返す値 
// 【戻値】
//   truepart : 評価した式がTrueのとき、falsepart : 評価した式がFalseのとき 
//////////////////////////////////////////////////
FUNCTION IIF(expr, truepart, falsepart)
	IFB EVAL(expr) THEN
		RESULT = truepart
	ELSE
		RESULT = falsepart
	ENDIF
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現で検索した結果をMatchesコレクションとして返します。 
//////////////////////////////////////////////////
FUNCTION reExecute(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Execute(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str1 : 置換される文字列 
//   str2 : 置換後の文字列 
//   Pattern : 置換する文字列のパターン 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現置換後の文字列 
//////////////////////////////////////////////////
FUNCTION reReplace(str1, str2, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Replace(str1, str2)
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 正規表現による検索の対象となる文字列 
//   Pattern : 正規表現で使用するパターンを設定 
//   IgnoreCase : 大文字・小文字を区別しない場合はTrue、区別する場合はFalse 
//   Global : 文字列全体を検索する場合はTrue、しない場合はFalse 
// 【戻値】
//   正規表現にマッチするかどうか 
//////////////////////////////////////////////////
FUNCTION reTest(str, Pattern, IgnoreCase = TRUE, Global = TRUE)
	DIM re = CREATEOLEOBJ("VBScript.RegExp")
	re.Pattern = Pattern
	re.IgnoreCase = IgnoreCase
	re.Global = Global
	RESULT = re.Test(str)
FEND

//////////////////////////////////////////////////
// 【引数】
//   inputs : 繰り返す文字列 
//   multiplier : inputsを繰り返す回数 
// 【戻値】
//   inputsをmultiplier回を繰り返した文字列を返します 
//////////////////////////////////////////////////
FUNCTION strRepeat(inputs, multiplier)
	DIM res = ""
	FOR n = 1 TO multiplier
		res = res + inputs
	NEXT
	RESULT = res
FEND

//////////////////////////////////////////////////
// 【引数】
//   serial : シリアル値 
//   format : フォーマット 
// 【戻値】
//   数値を表示書式に基づいて変換した文字列 
//////////////////////////////////////////////////
FUNCTION text(serial, format, hour12 = FALSE)
	HASHTBL startDate
	startDate["明治"] = "1868/01/25"
	startDate["大正"] = "1912/07/30"
	startDate["昭和"] = "1926/12/25"
	startDate["平成"] = "1989/01/08"
	startDate["令和"] = "2019/05/01"
	
	DIM baseDate = "1899/12/30"
	
	SELECT TRUE
		CASE reTest(format, "\[h+\]")
			Matches = reExecute(format, "\[(h+)\]")
			DIM hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "^h+$")
			Matches = reExecute(format, "^(h+)$")
			hour = iif(hour12, Hour(serial) MOD 12, Hour(serial))
			RESULT = text(hour MOD 24, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE reTest(format, "\[m+\]")
			Matches = reExecute(format, "\[(m+)\]")
			RESULT = text(serial * 1440, strRepeat("0", LENGTH(Matches.Item(0).SubMatches(0))))
		CASE format = "m"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_MM, "0")
		CASE format = "mm"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_MM2
		CASE format = "n"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN
		CASE format = "nn"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_NN2
		CASE format = "s"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_SS, "0")
		CASE format = "ss"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_SS2
		CASE format = "yyyy"
			GETTIME(serial, baseDate)
			RESULT = G_TIME_YY4
		CASE format = "yy"
			GETTIME(serial, baseDate)
			RESULT = COPY(G_TIME_YY4, 3, 2)
		CASE format = "e"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 2018
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1988
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1925
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1911
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(serial, "yyyy") - 1867
			SELEND
		CASE format = "ee"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 2018, "00")
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1988, "00")
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1925, "00")
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1911, "00")
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0
					RESULT = text(text(serial, "yyyy") - 1867, "00")
			SELEND
		CASE format = "g"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "R"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "H"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "S"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "T"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "M"
			SELEND
		CASE format = "gg"
			RESULT = COPY(text(serial, "ggg"), 1, 1)
		CASE format = "ggg"
			SELECT TRUE
				CASE dateDiff("d", startDate["令和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "令和"
				CASE dateDiff("d", startDate["平成"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "平成"
				CASE dateDiff("d", startDate["昭和"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "昭和"
				CASE dateDiff("d", startDate["大正"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "大正"
				CASE dateDiff("d", startDate["明治"], text(serial, "yyyy/mm/dd")) >= 0;		RESULT = "明治"
			SELEND
		CASE format = "mmmmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 1)
		CASE format = "mmmm"
			DIM month[] = "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
			RESULT = month[text(serial, "m") - 1]
		CASE format = "mmm"
			RESULT = COPY(text(serial, "mmmm"), 1, 3)
		CASE format = "dd"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD2, "00")
		CASE format = "d"
			GETTIME(serial, baseDate)
			RESULT = text(G_TIME_DD, "0")
		CASE reTest(format, "^[ad]{3,4}$")
			Matches = reExecute(format, "([ad]{3,4})")
			GETTIME(serial, baseDate)
			RESULT = getWeekdayName(G_TIME_WW, Matches.Item(0).SubMatches(0))
		CASE reTest(format, "(0+\.?0+)?%")
			Matches = reExecute(format, "(0+\.?0+)?%")
			RESULT = text(serial * 100, Matches.Item(0).SubMatches(0)) + "%"
		CASE reTest(format, "^\[DBNum\d{1,4}\](.*?)$")
			Matches = reExecute(format, "^\[DBNum(\d{1,4})\](.*?)$")
			DIM value = VAL(Matches.Item(0).SubMatches(0))
			DIM sss = text(serial, Matches.Item(0).SubMatches(1))
			Matches = reExecute(sss, "(\D+)?(\d+)(\D+)?")
			DIM res = ""
			FOR m = 0 TO Matches.Count - 1
				serial = Matches.Item(m).SubMatches(1)
				SELECT value
					CASE 1, 2
						DIM n[][9] = "〇", "一", "二", "三", "四", "五", "六", "七", "八", "九", + _
										"", "壱", "弐", "参", "四", "伍", "六", "七", "八", "九"
						DIM a[][3] = "", "十", "百", "千", + _
										"", "拾", "百", "阡"
						DIM b[][3] = "", "万", "億", "兆", + _
										"", "萬", "億", "兆"
						DIM r = ""
						DIM j = 0
						type = value - 1
						REPEAT
							DIM str = ""
							DIM n4 = serial MOD 10000
							FOR i = LENGTH(n4) TO 1 STEP -1
								s = COPY(n4, i, 1)
								IFB s = 1 AND a[type][LENGTH(n4)-i] <> "" THEN
									str = IIF(s, a[type][LENGTH(n4)-i], "") + str
								ELSE	
									str = n[type][s] + IIF(s, a[type][LENGTH(n4)-i], "") + str
								ENDIF
							NEXT
							IF str <> "" THEN r = str + b[type][j] + r
							j = j + 1
							serial = INT(serial / 10000)
						UNTIL serial = 0
						res = res + Matches.Item(m).SubMatches(0) + r + Matches.Item(m).SubMatches(2)
					CASE 3
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_FULLWIDTH) + Matches.Item(m).SubMatches(2)
					CASE 4
						res = res + Matches.Item(m).SubMatches(0) + STRCONV(serial, SC_HALFWIDTH) + Matches.Item(m).SubMatches(2)
				SELEND
			NEXT
			RESULT = res
		CASE reTest(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			Matches = reExecute(format, "^(.*?)(AM\/PM|am\/pm|A\/P|a\/p)(.*?)$")
			DIM array = SPLIT(Matches.Item(0).SubMatches(1), "/")
			ampm = array[IIF(serial - INT(serial) >= 0.5, 1, 0)]
			hour12 = TRUE
			res = ""
			WITH Matches.Item(0)
				res = text(serial, .SubMatches(0), hour12) + ampm + text(serial, .SubMatches(2), hour12)
			ENDWITH
			RESULT = res
		CASE reTest(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			Matches = reExecute(format, "([^ymdagehns]{0,})?(([ymdagehns])\3{0,})([^ymdagehns]+)?")
			FOR n = 0 TO Matches.Count - 1
				IF n = 0 THEN res = Matches.Item(n).SubMatches(0)
			NEXT
			FOR n = 0 TO Matches.Count - 1
				WITH Matches.Item(n)
					res = res + text(serial, .SubMatches(1), hour12) + .SubMatches(3)
				ENDWITH
			NEXT
			RESULT = res
		CASE reTest(format, "(0+)\.?(0+)?") AND UBound(SPLIT(format, ".")) <= 1 
			Matches = reExecute(format, "(0+)\.?(0+)?")
			len1 = LENGTH(Matches.Item(0).SubMatches(0))
			len2 = LENGTH(Matches.Item(0).SubMatches(1))
			DIM arr[] = LENGTH(INT(serial)), len1
			IFB POS(".", format) THEN
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX) + len2 + 1, len2), " ", "0")
			ELSE
				RESULT = REPLACE(FORMAT(serial, CALCARRAY(arr, CALC_MAX)), " ", "0")
			ENDIF
	SELEND
FEND

//////////////////////////////////////////////////
// 【引数】
//   str : 時刻文字列。hh:nn:ss AM/PM、hh:nn:ss、hh:nn AM/PM、hh:nn、h AM/PM 
// 【戻値】
//   シリアル値 (例)0…00:00:00、0.5…12:00:00、0.999988425925926…23:59:59 
//////////////////////////////////////////////////
FUNCTION timeValue(str)
	HASHTBL Pattern
	Pattern["hour"] = "(1[0-9]|2[0-4]|0?[0-9])"
	Pattern["minute"] = "([1-5][0-9]|60|0?[0-9])"
	Pattern["second"] = "([1-5][0-9]|60|0?[0-9])"
	SELECT TRUE
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(3), "AM|am"), 0, 12))/ 24 + .SubMatches(1) / 1440 + .SubMatches(2) / 86400
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + pattern["second"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + ":" + Pattern["second"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440) + (.SubMatches(2) / 86400)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(2), "AM|am"), 0, 12)) / 24 + .SubMatches(1) / 1440
			ENDWITH
		CASE reTest(str, Pattern["hour"] + ":" + Pattern["minute"])
			Matches = reExecute(str, Pattern["hour"] + ":" + Pattern["minute"])
			WITH Matches.Item(0)
				time = (.SubMatches(0) / 24) + (.SubMatches(1) / 1440)
			ENDWITH
		CASE reTest(str, Pattern["hour"] + "\s?([AP]M)")
			Matches = reExecute(str, Pattern["hour"] + "\s?([AP]M)")
			WITH Matches.Item(0)
				time = (VAL(.SubMatches(0)) + IIF(reTest(.SubMatches(1), "AM|am"), 0, 12)) / 24
			ENDWITH
	SELEND
	RESULT = time
FEND

//////////////////////////////////////////////////
// 【引数】
//   配列 : 上限値を求める配列 
// 【戻値】
//   配列の上限値 
//////////////////////////////////////////////////
FUNCTION UBound(array[])
	RESULT = RESIZE(array)
FEND
  1. CREATEOLEOBJ
  2. Shell.NameSpace
  3. Shell.Folder.Items
  4. Shell.Folder.GetDetailsOf
  5. Shell.FolderItems.Count
  6. Shell.FolderItem.IsFolder
  7. timeValue
  8. text
結果
09:24:43