我有两个Date对象,我需要得到时间差,这样我就可以确定它们之间的总小时数.他们碰巧是在同一天.我想要的结果是小时和分钟.
当我在我的Date对象上使用.toString()时,我得到了这个:Fri Dec 18 08:08:10 CST 2009
我尝试过以下方法:
long diff=(this.endDate.getTime()-this.startDate.getTime())/(60*60 * 1000);
Run Code Online (Sandbox Code Playgroud)
但这只给我几小时,而不是分钟.我知道这是一个简单的问题,但我无法理解它.
编辑:感兴趣的人的最终解决方案.感谢Michael Brewer-Davis
Period p = new Period(this.startDate, this.endDate);
long hours = p.getHours();
long minutes = p.getMinutes();
String format = String.format("%%0%dd", 2);
return Long.toString(hours)+":"+String.format(format, minutes);
Run Code Online (Sandbox Code Playgroud) 我的程序成功创建并填充了Excel(.xls)文件.一旦创建,我希望在系统的默认程序(在我的情况下为Excel)中打开新文件.我怎样才能做到这一点?
对于我想在记事本中打开txt文件的旧程序,我使用了以下内容:
if (!Desktop.isDesktopSupported()) {
System.err.println("Desktop not supported");
// use alternative (Runtime.exec)
return;
}
Desktop desktop = Desktop.getDesktop();
if (!desktop.isSupported(Desktop.Action.EDIT)) {
System.err.println("EDIT not supported");
// use alternative (Runtime.exec)
return;
}
try {
desktop.edit(new File(this.outputFilePath));
} catch (IOException ex) {
ex.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将此代码用于Excel文件时,它会给我以下错误:
java.io.IOException: Failed to edit file:C:/foo.xls
Run Code Online (Sandbox Code Playgroud)
建议?
按照本指南,我试图使用亚马逊的EC2设置Ruby on Rails.对于我的实例,我选择了"基本的32位Amazon Linux AMI 2010.11.1 Beta".我安装了ruby,sqlite和rubygems.我在链接指南的步骤3.3中运行以下命令
捆绑安装
结果如下.我确定我错过了一些东西,但我很茫然.有什么建议?
Installing sqlite3 (1.3.3) with native extensions /usr/lib/ruby/site_ruby/1.8/rubygems /installer.rb:529:in `build_extensions': ERROR: Failed to build gem native extension (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/ruby.h
Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-1.3.3 for inspection.
Run Code Online (Sandbox Code Playgroud)
编辑:按照下面的建议安装ruby-devel,我现在除了原始错误之外还得到此错误.
Installing sqlite3 (1.3.3) with native extensions /usr/lib/ruby/site_ruby/1.8/rubygems/installer.rb:529:in `build_extensions':
ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/usr/bin/ruby extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'port install sqlite3 +universal'
or …Run Code Online (Sandbox Code Playgroud)