现需得到一个 yyyy-MM-dd-hhmmss 这种格式命名的文件用到的代码如下
public void ImageCapture() {
File DatalDir = Environment.getExternalStorageDirectory();
File myDir = new File(DatalDir, "/DCIM/Camera");
myDir.mkdirs();
String mDirectoryname = DatalDir.toString() + "/DCIM/Camera";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hhmmss",
Locale.SIMPLIFIED_CHINESE);
File tempfile = new File(mDirectoryname, sdf.format(new Date())
+ ".jpg");
if (tempfile.isFile())
tempfile.delete();
Uri Imagefile = Uri.fromFile(tempfile);
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Imagefile);
startActivityForResult(cameraIntent, REQ_CODE_CAMERA);
}
可 File tempfile = new File(mDirectoryname, sdf.format(new Date())+ ".jpg"); 这行代码一直报错,提示 new Date()用法不对,(好像是说参数问题)现问:1 这是什么问题
2 如何修改上面的代码才能得到 yyyy-MM-dd-hhmmss 这种格式命名的文件
thanks
public void ImageCapture() {
File DatalDir = Environment.getExternalStorageDirectory();
File myDir = new File(DatalDir, "/DCIM/Camera");
myDir.mkdirs();
String mDirectoryname = DatalDir.toString() + "/DCIM/Camera";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd-hhmmss",
Locale.SIMPLIFIED_CHINESE);
File tempfile = new File(mDirectoryname, sdf.format(new Date())
+ ".jpg");
if (tempfile.isFile())
tempfile.delete();
Uri Imagefile = Uri.fromFile(tempfile);
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Imagefile);
startActivityForResult(cameraIntent, REQ_CODE_CAMERA);
}
可 File tempfile = new File(mDirectoryname, sdf.format(new Date())+ ".jpg"); 这行代码一直报错,提示 new Date()用法不对,(好像是说参数问题)现问:1 这是什么问题
2 如何修改上面的代码才能得到 yyyy-MM-dd-hhmmss 这种格式命名的文件
thanks
解决方案 »
- (Android) Eclipse "launching delegate" 停在 27%...
- ubuntu环境下, svn 如可导入项目源码?
- Android2.3目录结构怎样?
- 使画面中背景变暗的方法
- ExpandableListView中如何删除指定位置的child元素?
- 请问android如何在一个应用关闭的时候执行一个方法??
- android 2.3.5 JSONObject 解析出错,4.0 上OK
- 求demo ,或思路。动态添加activity,
- progurad 之后报错误
- android播放amr格式音频文件的问题
- ListView 中加入 EditText后的焦点问题
- 求android源码
java.util.Date你import的是哪个?
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
String dateline = ">> 发送时间:" + sdf.format(new Date(Long.valueOf(raw_dateline)*1000L));
这是我的开发代码样例。
"yyyy-MM-dd-hhmmss");
System.out.println("" + simpleDateFormat.format(new Date()));
输出:2011-12-16-101153。木有问题啊
import java.util.Date;