日期和时间格式 [英] Date and Time Format

查看:190
本文介绍了日期和时间格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候语!

我做了一个项目,可以将GPS坐标的手机号码自动接到类似这样的例子格式为纬度:14.7836139长:12.71104速度:0.0日期:1309325189000 收件人结果
现在我想的日期和时间,像这样的日期格式:DD / MM / YY HH:MM 任何人谁可以帮助我

这是我的样品code我用。

 公共无效onLocationChanged(位置LOC){loc.getLatitude();loc.getLongitude();
字符串文本=纬度:+ loc.getLatitude()+
+长:+ loc.getLongitude()+
+速度:+ loc.getSpeed​​()+
+日期:+ loc.getTime();Toast.makeText(getApplicationContext(),文本,Toast.LENGTH_SHORT).show();
字符串PHONENO = txtPhoneNo.getText()的toString()。
如果(phoneNo.length()大于0&放大器;&放大器; Text.length()大于0)
    sendSMS(PHONENO,文本);
}


解决方案

SimpleDateFormat的应该做的伎俩,然后你可以设置的格式掩盖自己。另外,您可以使用android时间类,但就是有点比较麻烦面具明智的。

 的SimpleDateFormat dateTimeFormat =新的SimpleDateFormat(DD / MM / YY HH:MM);
dateTimeFormat.format(新日期(loc.getTime()));

Greeting!

I've done a project that can send GPS Coordinates to mobile number Automatically, The Recipients received like this example format "lat:14.7836139 long:12.71104 speed:0.0 Date:1309325189000"
and now I want a format for a date and time like this Date:dd/mm/yy hh:mm Anyone who can Help me?

here is my sample code I use.

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);               


}

解决方案

SimpleDateFormat should do the trick, you can then set the format mask yourself. Alternatively you could use the android Time class, but that is a bit more tricky mask wise.

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

这篇关于日期和时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆