JAVA日历编译器

JAVA日历编译器

import javafx.scene.input.DataFormat;
import org.junit.Test;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class gaohaihen {
public static void main(String[] args) {
String str=“0”;
try {
System.out.println(str.length());
} catch (Exception e) {

    }
}
@Test
public void testDateFormat(){
    //显示当前时间
    //SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd HH:mm:ss");
    //String formatDate = format.format(new Date());
    //System.out.println(formatDate);
    //将当前时间转换成毫秒值

    //Date date = new Date();
   // long time = date.getTime();
    //System.out.println(time);

    long value=1594811272718L;
    SimpleDateFormat format = new SimpleDateFormat("yyyy年MM月dd日");

    String result= format.format(new Date(value));
    System.out.println(result);
}

@Test
public void testCalendar(){
Calendar c = Calendar.getInstance();
int weekYear = c.getWeekYear();
System.out.println(weekYear);
Date time = c.getTime();
System.out.println(time);
}
@Test
public void age(){
Date date=new Date();
DateFormat dateFormat=new SimpleDateFormat(“yyyy-MM-dd”);
try {
Date myDate=dateFormat.parse(“2000-04-13”);//将其转化为电脑格式
long cha=date.getTime()-myDate.getTime();//毫秒
int day= (int) (cha/(1000606024)); //6060
//一个小时60分钟一分钟60秒1秒1000毫秒1天24小时
System.out.println(day);
} catch (ParseException e) {
e.printStackTrace();
}

}

}

你可能感兴趣的:(JAVA)