现需得到一个 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

解决方案 »

  1.   

    java.sql.Date
    java.util.Date你import的是哪个?
      

  2.   

    sdf.ToString("yyyy-MM-dd-hhmmss") 这样就好了
      

  3.   


    SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");
    String dateline = ">> 发送时间:" + sdf.format(new Date(Long.valueOf(raw_dateline)*1000L));
    这是我的开发代码样例。
      

  4.   

    SimpleDateFormat simpleDateFormat = new SimpleDateFormat(
    "yyyy-MM-dd-hhmmss");
    System.out.println("" + simpleDateFormat.format(new Date()));
    输出:2011-12-16-101153。木有问题啊
      

  5.   

    import java.text.SimpleDateFormat;
    import java.util.Date;