Skip to content

Instantly share code, notes, and snippets.

@naijab
Created March 5, 2017 09:16
Show Gist options
  • Save naijab/6e071dd66cc5bd7194d74989c372a45f to your computer and use it in GitHub Desktop.
Save naijab/6e071dd66cc5bd7194d74989c372a45f to your computer and use it in GitHub Desktop.
วิธีแปลง ค.ศ.เป็น พ.ศ.
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