重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
时间格式化输出主要有两种方式,代码如下:
网站建设哪家好,找创新互联建站!专注于网页设计、网站建设、微信开发、小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了长兴免费建站欢迎大家使用!
//使用Calendar
Calendar now = Calendar.getInstance();
System.out.println("年:" + now.get(Calendar.YEAR));
System.out.println("月:" + (now.get(Calendar.MONTH) + 1));
System.out.println("日:" + now.get(Calendar.DAY_OF_MONTH));
System.out.println("时:" + now.get(Calendar.HOUR_OF_DAY));
System.out.println("分:" + now.get(Calendar.MINUTE));
ystem.out.println("秒:" + now.get(Calendar.SECOND));
//使用Date
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("当前时间:" + sdf.format(d));
扩展资料
JAVA中获取当前系统时间。
import java.util.Date;
import java.text.SimpleDateFormat;
public class NowString {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
}
参考资料来源:百度百科:Java
使用SimpleDateFormat即可,代码如下
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtil {
public static String formatDate(Date date)throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.format(date);
}
public static Date parse(String strDate) throws ParseException{
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return sdf.parse(strDate);
}
}
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
public class FormateBankAccountId {
ListString standardBankAccountIdFormat ;
public FormateBankAccountId(String propertiesFileName) throws FileNotFoundException, IOException
{
// 加载资源文件
Properties properties = new Properties();
properties.load(new FileReader(propertiesFileName));
this.standardBankAccountIdFormat = new ArrayListString();
int keyNumber = 1;
String value = null;
// 读取键值对,键的格式是: formate_1 ,..., formate_10,...,formate_100 等
while( ( value = properties.getProperty("formate_" + keyNumber++) ) != null)
{
value = value.trim();
this.standardBankAccountIdFormat.add(value);
}
}
public ListString formate(String orginalBankAccountId)
{
ListString proceededlBankAccountIds = new :
import java.util.*;
class gongzi {
public static void main(String[] args) {
Scanner kb = new Scanner(System. in );
int n = kb.nextInt();
String name = "";
double d = 0;
double e = 0;
double g = 0;
double k = 0;
for (int i = 0; i n; i++) {
name = kb.next();
d = kb.nextDouble();
e = kb.nextDouble();
g = kb.nextDouble();
k = e + d - g;
}
kb.close();
System.out.printf("%s,Salary is: %.2f + %.2f - %.2f = %.2f%n", name, d, e, g, k);
}
}