Skip to content

{{format-time}}

Behaves like the {{format-date}} helper, except it focuses on the time.

gts
import type { TOC } from '@ember/component/template-only';
import { formatTime } from 'ember-intl';

interface ExampleSignature {
  Args: {};
}

const today = new Date();

const Example: TOC<ExampleSignature> = <template>
  {{formatTime today}}
</template>;

export default Example;

options.format

In app/ember-intl.{js,ts}, you can use the formatTime key to define the formats that you want to reuse for the helper. Pass the name of your format to format.

gts
import type { TOC } from '@ember/component/template-only';
import { formatTime } from 'ember-intl';

interface ExampleSignature {
  Args: {};
}

const today = new Date();

const Example: TOC<ExampleSignature> = <template>
  {{formatTime today format="hhmmss"}}
</template>;

export default Example;
ts
import type { Formats } from 'ember-intl';

export const formats: Formats = {
  formatTime: {
    hhmmss: {
      hour: 'numeric',
      minute: 'numeric',
      second: 'numeric',
    },
  },
};

options.locale

You can display the text in another locale (i.e. independently from the user's preferred locale). Pass the name of the locale to locale.

gts
import type { TOC } from '@ember/component/template-only';
import { formatTime } from 'ember-intl';

interface ExampleSignature {
  Args: {};
}

const today = new Date();

const Example: TOC<ExampleSignature> = <template>
  <div lang="en-us">
    {{formatTime today locale="en-us"}}
  </div>

  <div lang="de-de">
    {{formatTime today locale="de-de"}}
  </div>
</template>;

export default Example;

Additional options

You can use named arguments to pass the options that Intl.DateTimeFormat supports. Some of these options are listed below.

  • hour12
  • timeStyle
  • timeZone
  • weekday
gts
import type { TOC } from '@ember/component/template-only';
import { formatTime } from 'ember-intl';

interface ExampleSignature {
  Args: {};
}

const today = new Date();

const Example: TOC<ExampleSignature> = <template>
  {{formatTime today timeStyle="full" timeZone="America/New_York"}}
</template>;

export default Example;