자바 의 시간 날짜 API 활용

13182 단어 #자바 기반
package com.guaji.exer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;

import org.junit.Test;

public class DateExer {
	
	/*	 java.lang.System 
	 * System    public static long currentTimeMillis()         1970 1 1 0 0 0             。
	 * java.util.Date
	 * 			--------java.sql.Date
	 * 	                  
	 * 	1:    :Date():           Date  
	 * 	2:    :Date(long i):        date  
	 * 	    :
	 * 	1:toString():      , , , , , 
	 * 	2:getTime():    Date        (   )
	 * 
	 * 	Calendar(  ) 	    abstract
	 * 		        
	 * */
		@Test
		public void localDate(){
			 LocalDate now = LocalDate.now();
			 System.out.println(now);
			 LocalTime now2 = LocalTime.now();
			 System.out.println(now2);
			 LocalDateTime now3 = LocalDateTime.now();
			 System.out.println(now3);
		 String format = DateTimeFormatter.ofPattern("yyy-MM-dd").format(now3);
		 System.out.println(format);
			 
		
			 
		}
	
		@Test
		public void DateExer1(){
			long currentTimeMillis = System.currentTimeMillis();
			System.out.println(currentTimeMillis);
				Date date=new Date();//           Date
				System.out.println(date);
				System.out.println(date.getTime());//    Date        (   )
				
				Date date2 = new Date(date.getTime());//        date  
				System.out.println(date2.toString());
				
				/**************************************************************/
				
				//Java.sql.Date              
					java.sql.Date date3 = new java.sql.Date(date.getTime());
					System.out.println(date3);
					
					Calendar instance = Calendar.getInstance();
					System.out.println(instance.getClass());//GregorianCalendar				
				
		}
		
		@Test
		public void SimpleDateFormatExer() throws ParseException{
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat();
			String format = simpleDateFormat.format(new Date());	//           20-7-22   3:47
			System.out.println(format);
			
			SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyy-MM-dd");
			System.out.println(simpleDateFormat2.format(new Date()));	//2020-07-22
			
			String date="2020-07-22";
			Date date2 = simpleDateFormat2.parse(date);	//             ,       
			System.out.println(date2);
			
	
			
		}
		
}

좋은 웹페이지 즐겨찾기