---
title: "日期“天数+1”的多种方法"
author: "lylegend13"
date: "2011-11-11T17:13:31Z"
tags: []
categories: ["编程语言"]
slug: "1"
draft: false
lastmod: "2011-11-11T17:20:08Z"
id: 1254517
url: "https://lltobe.iteye.com/blog/1254517"
---

说明：准确打印出日期，从今天到明年的今天，主要是2月。

 

1

 

```
import java.text.SimpleDateFormat;
import java.util.Date;

public class test {
	public static void main(String[] args) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date d = new Date();
		int oneDayTime = 24 * 60 * 60 * 1000;

		long time = d.getTime();
		for (int i = 0; i < 365; i++) {

			System.out.println(df.format(d));
			time += oneDayTime;
			d.setTime(time);
		}
	}
}
```

 2

 

```
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

public class test {
	public static void main(String[] args) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		for (int i = 0; i < 365; i++) {
			gc.add(Calendar.DAY_OF_MONTH, 1);
			System.out.println(df.format(gc.getTime()));
		}
	}
}
```

  3

 

```
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class test {
	public static void main(String[] args) {
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		for (int i = 0; i < 365; i++) {
			System.out.println(df.format(calendar.getTime()));
			calendar.add(Calendar.DAY_OF_MONTH, 1);
		}
	}
}
```