> For the complete documentation index, see [llms.txt](https://ankang.gitbook.io/commons/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ankang.gitbook.io/commons/commons-beans/gong-neng/ri-qi-zhuan-huan.md).

# 日期转换

对于常用的日期和字符串之间的互相转换，使用者只需将日期格式配置到`@Mapping`注解的`datePattern`属性中，即可完成自动转换。

```java
class Foo {
    Date date = new Date(0);
    
}
class FooDto {
    @Mapping(datePattern="yyyy-MM-dd")
    String date;
}

FooDto fooDto = BeanUtils.copyProperties(foo, FooDto.class);

System.out.println(fooDto.getDate()); // "1970-01-01"
```

{% hint style="info" %}
缺省会按照ISO本地标准时间格式`yyyy-MM-dd'T'HH:mm:ss`进行转换
{% endhint %}
