Skip to content

Instantly share code, notes, and snippets.

@victorbrndls
Created May 13, 2021 11:24
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 victorbrndls/24b83e010e8db9818cff7d4b615547f9 to your computer and use it in GitHub Desktop.
Save victorbrndls/24b83e010e8db9818cff7d4b615547f9 to your computer and use it in GitHub Desktop.
val isoFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")
fun Date.toISOFormat() : String = isoFormatter.format(this)
@jharman-notion
Copy link

Please be careful!. SimpleDateFormat is NOT thread safe, so re-using it to format multiple dates is not a good practice.

val isoFormatter get() = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS")

will give you a new instance for every call. I would suggest this instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment