Last Updated: February 25, 2016
·
3.778K
· samd

CoffeeScript Pretty Date formatting

To format a javascript date as a string in the form dd/mm/yy using coffeescript:

zero_pad = (x) ->
  if x < 10 then '0'+x else ''+x

Date::pretty_string = ->
  d = zero_pad(this.getDate())
  m = zero_pad(this.getMonth() + 1)
  y = this.getFullYear()
  y + m + d