|
|
|
Android - ขอคำแนะนำจากผู้รู้เกี่ยวกับ Format Datetime หน่อยครับ |
|
|
|
|
|
|
|
Code (Java)
package com.java.myapp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class MyClass {
public static void main(String[] args) {
String sDate = "2013-08-12";
System.out.println("Date Thai : " + dateThai(sDate));
}
public static String dateThai(String strDate)
{
String Months[] = {
"ม.ค", "ก.พ", "มี.ค", "เม.ย",
"พ.ค", "มิ.ย", "ก.ค", "ส.ค",
"ก.ย", "ต.ค", "พ.ย", "ธ.ค"};
DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
int year=0,month=0,day=0;
try {
Date date = df.parse(strDate);
Calendar c = Calendar.getInstance();
c.setTime(date);
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DATE);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return String.format("%s %s %s", day,Months[month],year+543);
}
}
Java Date Thai Format
ใช้ Java ไม่ยากครับ
|
|
|
|
|
Date :
2014-01-10 11:36:06 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|