---
title: "date"

doc_type: static
doc_category: static
doc_version: v20260901
source_url:
  html: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/format/date'
  md: 'https://developer.shopline.com/zh-hans-cn/docs/handlebars/helpers/format/date.md'
---


# date

将时间戳转换为另一种日期格式。

输出格式可以参考[Ruby documentation](https://ruby-doc.org/core-3.1.1/Time.html#method-i-strftime)。

## 参数

- `time` `{String}` 时间, 必填
- `format` `{String}` 格式, 可选
- `hash.format` `{String}` 格式, 可选
- `returns` `{String}` 时间字符串

## 用法

```handlebars
{{date string string}}
```

## 例子

<Example data={['article.created_at']}>
```handlebars
{{ date article.created_at '%B %d, %Y' }}
```
</Example>

### 当前日期

您可以将`date` helper 应用于关键字`'now'`并`'today'`输出当前时间戳。

:::note{title='Note'}
时间戳将反映上次渲染 Handlebars 的时间。因此，时间戳可能不会针对每个页面视图进行更新，具体取决于上下文和缓存。
:::

<Example>
  ```handlebars
  {{ date 'now' '%B %d, %Y' }}
  ```
</Example>

### 格式

```handlebars
{{date string string}}
{{date string format=string}}
```

指定可识别区域设置的日期格式。您可以使用以下格式：

- `abbreviated_date`
- `basic`
- `date`
- `date_at_time`
- `default`
- `on_date`

<Example data={['article.created_at']}>
```handlebars
{{ date article.created_at 'abbreviated_date' }}
```
</Example>