External packages are not required if you simply have two datetime formats. Just run both formats through the parser and take the non-missing one:
x <- c("7/12/2015 15:28","18-04-2016 18:20")
pmax(
as.POSIXct(x, format="%m/%d/%Y %H:%M", tz="UTC"),
as.POSIXct(x, format="%d-%m-%Y %H:%M", tz="UTC"),
na.rm=TRUE
)
#[1] "2015-07-12 15:28:00 UTC" "2016-04-18 18:20:00 UTC"
As far as I know, there is absolutely no way to deal with ambiguous date formats automatically, so hard-coding is the way to go here probably.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…