My program accepts date in the format of “yyyymmdd”, I don’t know how to check if it’s a weekday or not. I’ve seen ppl using $(date +%u) -gt 5 or "$(date +%a)" in Sat|Sun echo "weekend" in other threads, but that ${date} is like Tue Nov 22 14:16:35 EST 2011 I guess. So is there a good way to convert “yyyymmdd” to ${date} format? Or is there a simple way to check if “yyyymmdd” is a weekday or not? Any language is fine. Thanks.
My program accepts date in the format of yyyymmdd, I don’t know how to
Share
Any language? In Java I’d use
SimpleDateFormator Joda Time’sDateTimeFormatter. In C# I’d either useDateTime.ParseExactor Noda Time‘sLocalDatePattern. In all of these cases, the result is a value which can be asked for things like the day of the week.In Python I suspect you want
datetime.strptime, e.g.This is completely untested, however…