Skip to content

Instantly share code, notes, and snippets.

@GuilhermeRossato
Created July 30, 2021 02:41
Show Gist options
  • Select an option

  • Save GuilhermeRossato/2d54f5000faf3b7f81b55c500b5a8a4c to your computer and use it in GitHub Desktop.

Select an option

Save GuilhermeRossato/2d54f5000faf3b7f81b55c500b5a8a4c to your computer and use it in GitHub Desktop.
Get Brazilian Date Time String (UTC-3) - A javascript function to return a datetime string in UTC-3 in the format "yyyy/mm/dd hh:mm:ss" from a Date object
/**
* Returns a UTC-3 datetime string from a given date object
* @param {Date} date The date to retrieve the string from (default current date)
* @returns {'2021-07-29 23:37:25' | string} A string in the format "yyyy/mm/dd hh:mm:ss"
*/
function getBrazilianDateTimeString(date = new Date()) {
date.setTime(date.getTime() - 3 * 60 * 60 * 1000);
return date.toISOString().replace("T", " ").split(".")[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment