Time conversion
Posted: 2 Feb 2016 18:37
Hi,
Is it possible to convert "05:56PM" to "17:56" with VP 7.2 ?
Is it possible to convert "05:56PM" to "17:56" with VP 7.2 ?
Visual Prolog Discussion forums
https://discuss.visual-prolog.com/
Code: Select all
GMT = gmtTime::new(),
TF = timeFormatter::new(),
TF:setFromString(GMT,"05:56PM","hh:mmtt"),
========================================
Dump: 2016/02/03 01:15:15
----------------------------------------
Exception: wrongStringFormat (com/visual-prolog/time/time_exception)
Input string does not correspond to format string and therefore cannot be converted
Time as string = 05:56PM
Format picture = hh:mmtt
Code: Select all
clauses
run() :-
T = time::newFromGMT(0),
Locale = T:locale,
T:locale :=
locale_api::makeLcId(
locale_api::makeLangId(locale_native::lang_english, locale_native::sublang_english_us),
locale_native::sort_default),
T:setFromString("05:56PM", "hh:mmtt"),
T:locale := Locale,
write(T:formatTime()).
Code: Select all
class facts
amPm : timeFormatter := mk_amPm().
class predicates
mk_amPm : () -> timeFormatter AmPmFormatter.
clauses
mk_amPm() = AmPm :-
AmPm = timeFormatter::new(),
AmPm:locale :=
locale_api::makeLcId(
locale_api::makeLangId(locale_native::lang_english, locale_native::sublang_english_us),
locale_native::sort_default).
clauses
run() :-
T = time::newFromGMT(0),
amPm:setFromString(T, "05:56PM", "hh:mmtt"),
write(T:formatTime()).
Code: Select all
T = time::newFromGMT(0),
amPm:setFromString(T, "28-12-2016-05:56PM", "dd-MM-yyyy-hh:mmtt"),
Code: Select all
clauses
run() :-
T = time::newFromGMT(0),
amPm:setFromString(T, "28-12-2016-05:56PM", "dd-MM-yyyy-hh:mmtt"),
write(T:formatShortDate(), " ", T:formatTime()).