Created
October 25, 2012 02:42
-
-
Save saltnlight5/3950151 to your computer and use it in GitHub Desktop.
tzconverter.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Usage | |
groovy tzconverter.groovy '2012-10-24 00:00 EST' | |
groovy tzconverter.groovy '2012-10-24 00:00 CST' EST | |
groovy tzconverter.groovy '2012-10-24 00:00 MST' EST | |
groovy tzconverter.groovy '2012-10-24 00:00 PST' EST | |
groovy tzconverter.groovy '2012-10-24 00:00 EDT' EST | |
*/ | |
fromDt = args[0] | |
toTz = args.length > 1 ? args[1] : TimeZone.getDefault().getID() | |
import java.text.* | |
fromDf = new SimpleDateFormat("yyyy-MM-dd HH:mm z") | |
toDf = new SimpleDateFormat("yyyy-MM-dd HH:mm z") | |
toDf.setTimeZone(TimeZone.getTimeZone(toTz)) | |
dt = fromDf.parse(fromDt) | |
result = toDf.format(dt) | |
println fromDt | |
println result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment