标签:mon fir 距离 timezone ngx simple ase out shang
Data类:从1970.1.1.0点开始到某个时刻的毫秒数,类型是long
//Date的默认构造方法,返回当前系统时间
public Date() { this(System.currentTimeMillis());}
//Date的常用构造方法,可以传入年月日时分秒
public Date(int year, int month, int date)
{ this(year, month, date, 0, 0, 0);}
//构造方法(全)
public Date(int year, int month, int date, int hrs, int min, int sec) {
int y = year + 1900;
// month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
if (month >= 12) {
y += month / 12;
month %= 12;
} else if (month < 0) {
y += CalendarUtils.floorDivide(month, 12);
month = CalendarUtils.mod(month, 12);
}
BaseCalendar cal = getCalendarSystem(y);
cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
getTimeImpl();
cdate = null;
}
注:DateFormate类中的两个常用方法
DateFormat dateformat =new SimpleDateFormat("yyyy-MM-dd");
//因为DateFormat继承Format,所以这样写的好处是不用重写Format里的方法
dateformat.formate(Date date)
关于date的内容就放下面一段代码,自行体会:
package com.study.shangxuetang.cn.bjsxt.test;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;
/*
可视化日历程序
*/
public class VisualCalendar {
public static void main(String[] args) {
System.out.println("请输入日期(按照格式:2000-01-01)");
Scanner scanner = new Scanner(System.in);
String temp = scanner.nextLine();
//可视化日历程序
DateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar calendar = new GregorianCalendar();
Calendar firthDay = new GregorianCalendar();
try {
Date date = sDateFormat.parse(temp);
calendar.setTime(date);
System.out.println("今天是周"+(calendar.get(Calendar.DAY_OF_WEEK)-1));//获得今天是本周的周几.之所以要-1因为它本身是从周日开始算第一天的而非周一
System.out.println("今天是本月第"+calendar.get(Calendar.DAY_OF_MONTH)+"天");//获得今天是本周第几天
} catch (ParseException e) {
e.printStackTrace();
}
//得到是哪个月份
firthDay.set(Calendar.MONTH,calendar.get(Calendar.MONTH));
// Java中Calendar.MONTH返回的数值其实是当前月距离第一个月有多少个月份的数值,JANUARY在Java中返回“0”,所以我们需要+1。
System.out.println(firthDay.get(Calendar.MONTH));
firthDay.set(Calendar.DATE,1);
System.out.println(firthDay.get(Calendar.DAY_OF_WEEK));
System.out.println("日\t一\t二\t三\t四\t五\t六");
for (int i = 0; i < firthDay.get(Calendar.DAY_OF_WEEK)-1; i++) {
if(firthDay.get(Calendar.DAY_OF_WEEK) == 7)break;
System.out.print("\t");
}
int maxDate = firthDay.getActualMaximum(Calendar.DATE);//获得本月最大天数
int j = 0;
for (int i = 1; i <= maxDate; i++) {
if(i == calendar.get(Calendar.DAY_OF_MONTH)){
System.out.print("\033[31m"+"*"+i+"\t");
}else {
System.out.print("\033[29m"+i+"\t");
}
j++;
if(j == 7 && firthDay.get(Calendar.DAY_OF_WEEK) == 7){
System.out.print("\n");
}
if(j != 7 && (j + (firthDay.get(Calendar.DAY_OF_WEEK))-1) % 7 == 0){
System.out.print("\n");
}
// j = calendar.get(Calendar.DAY_OF_WEEK);
// if(j == Calendar.SATURDAY){
// System.out.print("\n");
// }
// calendar.add(Calendar.DATE,1);
}
}
}
关于Collection的内容放到集合框架中
标签:mon fir 距离 timezone ngx simple ase out shang
原文地址:https://www.cnblogs.com/panmao/p/12860374.html