Java Calendar获取年.月.日.时间 Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")); //获取东八区时间 int year = c.get(Calendar.YEAR); //获取年 int month = c.get(Calendar.MONTH) + 1; //获取月份,0表示1月份 int day = c.get(Calendar.DAY_OF_MONTH);
Calendar的使用举个小栗子: //通过当前时间获取本周周一时间 Date date = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(date ); calendar.add(Calendar.DATE,i + 1 - (calendar.get(Calendar.DAY_OF_WEEK) - 1) ); date = calendar.getTime();
开始使用new Date()测试,并用通过date.getMonth(),和date.getDay()获取,不过后来发现这两个访求是jdk1.1版本的,现在已经不用了,而且结果也不正确. ; int day = date.get(Calendar.DAY_OF_MONTH); 获取当前的月份和日期 试了一下,果然正确 后来查看java doc文档,MONTH字段解释如下 Field number for get and set indicating the month. This is a ca
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class TestDate { /** * 获取当前年份.月份.日期 * @param args */ public static void main(String[] args) { Calendar cale = null; cale = Calendar.getInstance(); int year =
public class CalendarTest { public static void main(String[] args) { // 获取当前年份.月份.日期 Calendar cale = null; cale = Calendar.getInstance(); int year = cale.get(Calendar.YEAR); int month = cale.get(Calendar.MONTH) + 1; int day = cale.get(Calendar.DATE);
We are given a 2-dimensional grid. "." is an empty cell, "#" is a wall, "@" is the starting point, ("a", "b", ...) are keys, and ("A", "B", ...) are locks. We start at the starting poin