Created
January 9, 2018 14:13
-
-
Save developer-sdk/cc6cab6c3ce602108ce24ace5490d2a7 to your computer and use it in GitHub Desktop.
SimpleDateFormat 이용하기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.text.DateFormat; | |
| import java.text.ParseException; | |
| import java.text.SimpleDateFormat; | |
| import java.util.Date; | |
| public class SimpleDateFormatPattern { | |
| public static String unixTimeToStrDate(String unixtime) { | |
| Date date = new Date(Long.parseLong(unixtime)); | |
| DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | |
| return formatter.format(date); | |
| } | |
| public static Date parseStrDate(String strDate) throws ParseException { | |
| DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); | |
| return formatter.parse(strDate); | |
| } | |
| public static String patternYandy(String unixtime) { | |
| Date date = new Date(Long.parseLong(unixtime)); | |
| DateFormat formatter = new SimpleDateFormat("YYYY yyyy ww"); | |
| return formatter.format(date); | |
| } | |
| public static void main(String[] args) throws ParseException { | |
| System.out.println(unixTimeToStrDate("1419984000000")); | |
| System.out.println(parseStrDate("2017-01-09")); | |
| // ------------------------------------------------------- | |
| System.out.println("----------------------"); | |
| System.out.println(patternYandy("1388188800000")); // 2013-12-28 토 | |
| System.out.println("----------------------"); | |
| System.out.println(patternYandy("1388275200000")); // 2013-12-29 일 | |
| System.out.println(patternYandy("1388361600000")); // 2013-12-30 월 | |
| System.out.println(patternYandy("1388448000000")); // 2013-12-31 화 | |
| System.out.println(patternYandy("1388534400000")); // 2014-01-01 수 | |
| System.out.println(patternYandy("1388620800000")); // 2014-01-02 목 | |
| System.out.println(patternYandy("1388707200000")); // 2014-01-03 금 | |
| System.out.println(patternYandy("1388793600000")); // 2014-01-04 토 | |
| System.out.println("----------------------"); | |
| System.out.println(patternYandy("1419984000000")); // 2014-12-31 토 | |
| System.out.println(patternYandy("1420070400000")); // 2015-01-04 토 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment