Articles on: Bots & Applications
This article is also available in:

How to change your application's timezone

How to Change Your Application's Timezone


Common Questions and Symptoms:

  • "My project/bot's time is wrong."
  • "My system is recording logs with a 3-hour difference (ahead or behind)."
  • "How do I change the timezone to Brasília time?"
  • "Why isn't the server time set to Brazil's time?"


Why Is the Project's Time Different?


Square Cloud servers are located in New York, USA. By default, the system timezone is configured to use UTC-0.


In this article, we show you how to customize your application's timezone for any desired region, correcting time discrepancies directly in your code.


How to Configure the Correct Timezone


Method 1 (simplest): the TZ environment variable


On most Linux runtimes you can set the timezone without touching your code: in the Square Cloud dashboard, under Environment Variables (ENV), add a TZ variable with your region (e.g. TZ=America/Sao_Paulo) and restart the app. If your runtime ignores TZ (some environments pin the clock to UTC), use the code method below, which always works.


Method 2 (guaranteed): convert in code


The following examples apply timezone conversions directly in code, in JavaScript and Python:


JavaScript


1. Using the Native API

const date = new Date();
const dateString = date.toLocaleString("pt-BR", { timeZone: "America/Sao_Paulo" });
console.log(dateString);


2. Using the Moment.js Library

const moment = require('moment');
require('moment-timezone');

const date = moment();
const time = date.tz('America/Sao_Paulo');

// Define the format string for date and time representation
// YYYY: Four-digit year (e.g., 2022)
// MM: Two-digit month (e.g., 01 for January)
// DD: Two-digit day of the month (e.g., 01)
// HH: Two-digit hour in 24h format (e.g., 13)
// mm: Two-digit minute (e.g., 05)
// ss: Two-digit second (e.g., 09)
const formattedTime = time.format('YYYY-DD-MM HH:mm:ss');
console.log(formattedTime); // Displays the date and time in the "America/Sao_Paulo" timezone


Python


1. Using the Native Library (timedelta)

from datetime import datetime, timedelta

# Creates a datetime object
now = datetime.now()

# Defines the timezone difference (-3 hours for America/Sao_Paulo)
time_difference = timedelta(hours=-3)

# Applies the difference to change the timezone
time = now + time_difference

# Formats date and time
formatted_time = time.strftime('%Y-%d-%m %H:%M:%S')
print(formatted_time) # Displays the date and time in the "America/Sao_Paulo" timezone


2. Using the Pytz Library

from datetime import datetime
import pytz

# Creates a datetime object in UTC
now = datetime.now(pytz.utc)

# Defines the "America/Sao_Paulo" timezone
tz = pytz.timezone('America/Sao_Paulo')

# Converts to the defined timezone
time = now.astimezone(tz)

# Formats date and time
formatted_time = time.strftime('%Y-%d-%m %H:%M:%S')
print(formatted_time) # Displays the date and time in the "America/Sao_Paulo" timezone

Updated on: 07/02/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!