안녕세계

[안드로이드] SimpleDateFormat (날짜형식 변경) 본문

[안드로이드] SimpleDateFormat (날짜형식 변경)

Junhong Kim 2016. 11. 1. 15:27
728x90
반응형
public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

String dateTime = "2016-11-01T15:25:31.000Z"; // 000 - 밀리 세컨드
SimpleDateFormat old_format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); // 받은 데이터 형식
old_format.setTimeZone(TimeZone.getTimeZone("KST"));
SimpleDateFormat new_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // 바꿀 데이터 형식

try {
Date old_date = old_format.parse(dateTime);
String new_date = new_format.format(old_date);

Log.i("inma", dateTime);
Log.i("inma", new_date);

} catch (ParseException e) {
e.printStackTrace();
Log.e("inma", e.toString());
}
}
}

※ 참고

http://blog.acronym.co.kr/350

728x90
반응형
Comments