Something like this?
i <- c("1day-2021-3-2--20-0.csv", "2day-2021-3-3--20-0.csv", "31day-2021-3-31--20-0.csv")
pattern <- "([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})"
m <- regexpr(pattern, i)
as.POSIXct(regmatches(i, m))
#> [1] "2021-03-02 CET" "2021-03-03 CET" "2021-03-31 CEST"
Created on 2021-03-03 by the reprex package (v1.0.0)