如何获得当前日期时间在安卓毫秒 [英] How to get current date time in milliseconds in android
本文介绍了如何获得当前日期时间在安卓毫秒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图用我的名字的文件保存为当前日期和时间以毫秒为单位。而在阅读文件,我想阅读最新one.Here是code
日历RightNow公司= Calendar.getInstance();
长偏移= rightNow.get(Calendar.ZONE_OFFSET)+ rightNow.get(Calendar.DST_OFFSET);
字符串sinceMidnight = Long.toString((rightNow.getTimeInMillis()+偏移量)%(24 * 60 * 60 * 1000));
返回sinceMidnight +_+文件名;
解决方案
我想你可以使用这个
很长一段时间= System.currentTimeMillis的();
这将返回当前时间以毫秒为单位的模式。这必将正常工作
很长一段时间= System.currentTimeMillis的();
android.util.Log.i时间(类,在millisecinds时间值+时间);
下面是一个使用上述功能我的logcat
05-13 14:38:03.149:INFO /时间类(301):时间millisecinds 1368436083157价值
如果你有与毫秒值的任何疑问。检查这里
修改:这是一个简单的方法。但是,如果你需要的时区或其他任何细节,我认为这是不够的 使用Android的API支持另见这个方法
i am trying to save my file with name as current date and time in milliseconds. and while reading file i want to read latest one.Here is the code
Calendar rightNow = Calendar.getInstance();
long offset = rightNow.get(Calendar.ZONE_OFFSET) + rightNow.get(Calendar.DST_OFFSET);
String sinceMidnight = Long.toString((rightNow.getTimeInMillis() + offset) % (24 * 60 * 60 * 1000));
return sinceMidnight+"_"+Filename;
解决方案
I think you can use this
long time= System.currentTimeMillis();
this will return current time in milliseconds mode . this will surely work
long time= System.currentTimeMillis();
android.util.Log.i("Time Class ", " Time value in millisecinds "+time);
Here is my logcat using the above function
05-13 14:38:03.149: INFO/Time Class(301): Time value in millisecinds 1368436083157
If you got any doubt with millisecond value .Check Here
EDIT: This is easy approach .but if you need time zone or any other details I think this won't be enough Also See this approach using android api support
这篇关于如何获得当前日期时间在安卓毫秒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文