Created
March 5, 2017 09:16
-
-
Save naijab/6e071dd66cc5bd7194d74989c372a45f to your computer and use it in GitHub Desktop.
วิธีแปลง ค.ศ.เป็น พ.ศ.
This file contains 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
SimpleDateFormat sourceFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
SimpleDateFormat destFormat = new SimpleDateFormat("dd MMM 'พ.ศ' yyyy"); //here 'a' for AM/PM | |
Date date = null; | |
try { | |
Calendar cal = Calendar.getInstance(); | |
cal.setTime(sourceFormat.parse("วันที่"); | |
cal.add(Calendar.YEAR, 543); //บวก 543 เพื่อกลายเป็น พ.ศ. | |
date = cal.getTime(); | |
// date = sourceFormat.parse(itemList.get(position).getNewsModified()); | |
} catch (ParseException e) { | |
e.printStackTrace(); | |
} | |
String formattedDate = destFormat.format(date); | |
m_date.setText(formattedDate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment