Skip to main content

useConvertDateToTimezone

Returns a function that converts a date to the timezone selected in MoBro.

JavaScript dates are always displayed in the timezone of the device running the dashboard. After converting a date, its local getters like getHours() return the time in the timezone selected in MoBro instead.

function useConvertDateToTimezone(): (date: Date) => Date

Returns

A function that takes a Date and returns the converted Date.

Example

src/widgets/example/Example.tsx
import React from 'react'
import {useConvertDateToTimezone} from '@modbros/dashboard-sdk'

export default function Example() {
const convertDate = useConvertDateToTimezone()
const date = convertDate(new Date())

return <span>{date.getHours()}:{date.getMinutes()}</span>
}