Android 如何获取日期和时间并将其保存在文本文件中?
我每半小时提取一次gps位置,并在textview中显示它,同时使用以下代码将textview中传递的值保存到sdcard gpsdata.txt文件中,但在这里我必须将其保存为时间和日期,并进行编号Android 如何获取日期和时间并将其保存在文本文件中?,android,date,time,gps,location,Android,Date,Time,Gps,Location,我每半小时提取一次gps位置,并在textview中显示它,同时使用以下代码将textview中传递的值保存到sdcard gpsdata.txt文件中,但在这里我必须将其保存为时间和日期,并进行编号 现在我在txt文件中获得了如下gps位置: 13.01471695,80.1469223 13.01471695,80.1469223 13.01471695,80.146922313.01471695,80.1469223 但我需要这样: 1) 13.01471695,80.14692
- 现在我在txt文件中获得了如下gps位置:
80.1469223 13.01471695,80.1469223
13.01471695,80.1469223
- 但我需要这样:
2)13.01471670,80.1469260时间:中午12:45日期:2013年1月1日
谢谢。行前
buf.append(text)代码>添加这行代码
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd/MM/yyyy");
String currentDateandTime = sdf.format(new Date());
text+=" "+currentDateandTime;
在buf.append(文本)行之前代码>添加这行代码
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm dd/MM/yyyy");
String currentDateandTime = sdf.format(new Date());
text+=" "+currentDateandTime;
下面是生成单个语句的代码,我假设您使用Location对象
13.01471695,80.1469223 time:12 30pm date:1/1/2013
Date locationDate = new Date(location.getTime());
StringBuilder sb = new StringBuilder(location.getLatitude())
.append(",")
.append(location.getLongitude())
.append("time:")
.append(timeFormat.format(locationDate))
.append(" date:")
.append(dateFormat.format(locationDate));
String locationDetail = sb.toString();
下面是生成单个语句的代码,我假设您使用Location对象
13.01471695,80.1469223 time:12 30pm date:1/1/2013
Date locationDate = new Date(location.getTime());
StringBuilder sb = new StringBuilder(location.getLatitude())
.append(",")
.append(location.getLongitude())
.append("time:")
.append(timeFormat.format(locationDate))
.append(" date:")
.append(dateFormat.format(locationDate));
String locationDetail = sb.toString();
为什么不为此使用SQLiteDatabase
,然后您可以简单地使用类似的方法插入具有当前日期时间的记录:
为什么不使用SQLiteDatabase
进行此操作,然后您可以简单地使用类似的方法插入具有当前日期时间的记录:
如果可以,我可以将其应用于文件输出流吗?请告诉我如何实现该目标。如果可以,我可以将其应用于文件输出流吗?如果可以,请告诉我如何实现该目标