์ƒˆ์†Œ์‹

๐Ÿ“ŒDevelop/โ˜•Java

[Basic] String to Date, Date to String ํ˜• ๋ณ€ํ™˜

  • -

 

 

QUOTE THE DAY

“ ์—๋Ÿฌ ์—†๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ๋งŒ๋“œ๋Š” ๋ฐ๋Š” ๋‘๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์„ธ๋ฒˆ์งธ ๊ฒƒ๋งŒ ์ž‘๋™ํ•œ๋‹ค. ”

- Alan J. Perlis (์•จ๋Ÿฐ J. ํŽ„๋ฆฌ์Šค)
 

Code

import java.text.SimpleDateFormat;
import java.util.Date;		
		
        //String to Date
        String str="2020-08-12 17:52:08";		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date strToDate=sdf.parse(str);	//return : Wed Aug 12 17:52:08 KST 2020		
        
        //Date to String
        SimpleDateFormat f1 = new SimpleDateFormat("yyyyMMdd");	
		SimpleDateFormat f2 = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat f3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		Date sysdate =  new Date();	//return : Wed Aug 12 17:52:08 KST 2020
        
		String sys1=f1.format(sysdate);
		String sys2=f2.format(sysdate);
		String sys3=f3.format(sysdate);
        
		System.out.println(sys1);	//return : 20200812
		System.out.println(sys2);	//return : 2020-08-12
		System.out.println(sys3);	//return : 2020-08-12 17:52:08

 

 

 

๋ฐ˜์‘ํ˜•

'๐Ÿ“ŒDevelop > โ˜•Java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

๋™์‹œ์„ฑ ์ด์Šˆ  (0) 2024.01.24
[Java] Collections / ์ž๋ฐ” ์ปฌ๋ ‰์…˜  (0) 2023.02.16
[Basic] String to int , int to String ํ˜•๋ณ€ํ™˜  (0) 2023.02.16
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.