27#Date&DateFormat&Calendar

Date

  • long System.currentTimeMillis()
  • 时间原点:1970年1月1日00:00:00

Date的构造方法

Date();

Date的方法

void setTime(long millis);
long getTime();

DateFormat

SimpleDteFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = sdf.format(new Date());
Date date = sdf.parse("1999-1-2 12:32:11");
System.out.println(date);

构造方法

SimpleDateFormat(String format);

方法

String format(Date d);
Date parse(String date);

Calendar

方法

static Calendar getInstance();
Date getTime();
static int YEAR;
static int MONTH; //0~11
static int DAY_OF_MONTH;
int get(int number);
void set(int field, int value); //(Calendar.YEAR,2018)
void set(int year, int month, int day); //2018,1,1-->显示:2018,2,1
void add(int field, int value); //日历的偏移量

猜你喜欢

转载自blog.csdn.net/weixin_43660263/article/details/86554347