---
title: "Calender to Date snip"
author: "lingceng"
date: "2013-05-30T10:25:17Z"
tags: []
categories: ["企业架构"]
slug: "calender-to-date-snip"
draft: false
lastmod: "2013-05-30T10:25:17Z"
id: 1879842
url: "https://lingceng.iteye.com/blog/1879842"
---

The format is not stored in the Date. It is stored in the String. The Date#toString() returns a fixed format which is described in its Javadoc.

Do the formatting only at the moment you need to display a Date to a human as a String.


```java
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 10);
Date date = calendar.getTime();
String formattedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
System.out.println(formattedDate);

```

Note that MM stands for months and mm for minutes. See also SimpleDateFormat javadoc.