Skip to content

Instantly share code, notes, and snippets.

@jacobbubu
Created April 20, 2013 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacobbubu/5425979 to your computer and use it in GitHub Desktop.
Save jacobbubu/5425979 to your computer and use it in GitHub Desktop.
localOffset = (new Date).getTimezoneOffset() * 60000
getLocaleStringByTimezoneOffset = (date, offset) ->
localTime = date.getTime()
utc = localTime + localOffset
offsetDate = utc + 3600000 * offset
nd = (new Date(offsetDate))
nd.toLocaleDateString() + ' ' + nd.toLocaleTimeString()
d = new Date()
console.log 'Beijing Time', getLocaleStringByTimezoneOffset d, 8.0
console.log 'Tokyo Time', getLocaleStringByTimezoneOffset d, 9.0
console.log 'Seattle Time', getLocaleStringByTimezoneOffset d, -8.0
console.log 'Australia Time', getLocaleStringByTimezoneOffset d, 11.0
console.log 'Hawaii Time', getLocaleStringByTimezoneOffset d, -10.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment