Skip to content

Instantly share code, notes, and snippets.

@Senorsen
Created February 23, 2016 04:06
Show Gist options
  • Save Senorsen/37e63ff4064b22789b5a to your computer and use it in GitHub Desktop.
Save Senorsen/37e63ff4064b22789b5a to your computer and use it in GitHub Desktop.
Get time in both Windows and Unix-like (in bash, etc.)
#!/bin/sh
# Originally from http://stackoverflow.com/questions/24538632/githubs-git-bash-msysgit-showing-wrong-timezone-on-windows
# and modified by Senorsen
# Are we running on Windows?
isWindows() { [[ -n "$WINDIR" ]]; }
# Get time, cross-platform.
getTime() {
if isWindows; then
echo `cmd.exe "/c echo %date%" | head -c 10 | sed 's/\//-/g'` `cmd.exe "/c echo %time%" | head -c 8 | tr ' ' 0`
else
date +"%Y-%m-%d %T"
fi
}
getTime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment