日期和时间格式

Thi*_*lle 5 java formatting time android

问候!

我做了一个项目,可以自动发送GPS坐标到手机号码,收件人收到像这样的例子格式" lat:14.7836139长:12.71104速度:0.0日期:1309325189000 "
现在我想要一个日期和时间格式这样日期:dd/mm/yy hh:mm任何可以帮助我的人?

这是我使用的示例代码.

public void onLocationChanged(Location loc)

{

loc.getLatitude();

loc.getLongitude();
String Text = "lat:" + loc.getLatitude() + " "
+ "long:" + loc.getLongitude()+" "
+ "speed:" + loc.getSpeed() +" " 
+ "date:" + loc.getTime();   

Toast.makeText( getApplicationContext(),

Text,

Toast.LENGTH_SHORT).show();
String phoneNo = txtPhoneNo.getText().toString();


if (phoneNo.length()>0 && Text.length()>0)                
    sendSMS(phoneNo, Text);               


}
Run Code Online (Sandbox Code Playgroud)

MrJ*_*Jre 0

SimpleDateFormat 应该可以解决问题,然后您可以自己设置格式掩码。或者,您可以使用 android Time 类,但这有点棘手。

SimpleDateFormat dateTimeFormat = new SimpleDateFormat("dd/MM/yy HH:mm");
dateTimeFormat.format(new Date(loc.getTime()));
Run Code Online (Sandbox Code Playgroud)