1. 如何用java语言 获得系统当前日期
java语言 获得系统当前日期:
1、Date date=new Date();这个是java提供的时间类,可以从中取出,年、月日、时、分、秒
2、SimpleDateFormat这个是时间格式类,对时间进行格式化
String time=new SimpleDateFormat("HH:mm:ss").format(new Date())
time=15:02:03
String time=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
time=2015-05-26 15:02:03
3、System.currentTimeMillis(),返回的是long型日期时间
long time=System.currentTimeMillis();
time=352632563256;
2. 【Java】怎样获取当前系统时间,需要的格式为yyyy-MM-dd HH:mm:ss
1、打开Eclipse的主界面,需要通过图示的按钮来引入java包。
3. 在JSP中加入Java代码获得系统时间
1、获取当前时间,和某个时间进行比较。此时主要拿long型的时间值。
方法如下:
要使用 java.util.Date 。获取当前时间的代码如下
代码如下 复制代码
Date date = new Date();
date.getTime() ;
还有一种方式,使用 System.currentTimeMillis() ;
都是得到一个当前的时间的long型的时间的毫秒值,这个值实际上是当前时间值与1970年一月一号零时零分零秒相差的毫秒数
一、获取当前时间, 格式为: yyyy-mm-dd hh-mm-ss
DateFormat.getDateTimeInstance(2, 2, Locale.CHINESE).format(new java.util.Date());
二、获取当前时间, 格式为: yyyy年mm月dd日 上午/下午hh时mm分ss秒
代码如下 复制代码
DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, Locale.CHINESE).format(new java.util.Date());
三、获取当前时间(精确到毫秒), 格式为: yyyy-mm-dd hh:mm:ss.nnn
代码如下 复制代码
new java.sql.Timestamp(System.currentTimeMillis()).toString();
一. 获取当前系统时间和日期并格式化输出:
代码如下 复制代码
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()为获取当前系统时间
}
}
4. JAVA中获取系统当前时间该怎么写
一. 获取当前系统时间和日期并格式化输出:x0dx0ax0dx0aimport java.util.Date; x0dx0aimport java.text.SimpleDateFormat;x0dx0ax0dx0apublic class NowString { x0dx0a public static void main(String[] args) { x0dx0a SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式x0dx0a System.out.println(df.format(new Date()));// new Date()为获取当前系统时间x0dx0a } x0dx0a} x0dx0ax0dx0a二. 在数据库里的日期只以年-月-日的方式输出,可以用下面两种方法:x0dx0ax0dx0a1、用convert()转化函数:x0dx0ax0dx0aString sqlst = "select convert(varchar(10),bookDate,126) as convertBookDate from roomBook where bookDate between -4-10' and -4-25'";x0dx0ax0dx0aSystem.out.println(rs.getString("convertBookDate")); x0dx0ax0dx0a2、利用SimpleDateFormat类:x0dx0ax0dx0a先要输入两个java包:x0dx0ax0dx0aimport java.util.Date; x0dx0aimport java.text.SimpleDateFormat;x0dx0ax0dx0a然后:x0dx0ax0dx0a定义日期格式:SimpleDateFormat sdf = new SimpleDateFormat(yy-MM-dd);x0dx0ax0dx0asql语句为:String sqlStr = "select bookDate from roomBook where bookDate between -4-10' and -4-25'";x0dx0ax0dx0a输出:x0dx0ax0dx0aSystem.out.println(df.format(rs.getDate("bookDate")));
5. java 如何获取当前系统时间
/**
* 获取当前系统时间
*
* @return 返回短时间字符串格式yyyy-MM-dd
*/
public static String getStringDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString;
}
**
* 获取当前系统时间
*
* @return返回短时间格式 yyyy-MM-dd
*/
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
6. 请问:怎么用java语言获取当前系统时间,以便自动插入数据库中
1.Date()+SimpleDateFormat()
DateFormatdateFormat=newSimpleDateFormat("yyyy/MM/ddHH:mm:ss");Datedate=newDate();System.out.println(dateFormat.format(date));
2.Calender()+SimpleDateFormat()
Calendarcal=Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
举个例子给你:
importjava.util.Date;
importjava.text.DateFormat;
importjava.text.SimpleDateFormat;
importjava.util.Calendar;
publicclassGetCurrentDateTime{
publicstaticvoidmain(String[]args){
DateFormatdateFormat=newSimpleDateFormat("yyyy/MM/ddHH:mm:ss");
//getcurrentdatetimewithDate()
Datedate=newDate();
System.out.println(dateFormat.format(date));
//()
Calendarcal=Calendar.getInstance();
System.out.println(dateFormat.format(cal.getTime()));
}
}
别忘了import
7. java怎么获取当前系统时间 毫秒数
首先获取当前时间:
java.util.Date nowdate = new java.util.Date();
2/2
然后如果你想时间的格式和你想用的时间格式一致 那么就要格式化时间了SimpleDateFormat 的包在java.text包下SimpleDateFormat
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") //年月日 时分秒
String t = sdf.parse(nowdate);
8. java 怎么调用当前时间 要详细的语句 谢谢
public static String getCurrentTime() {
java.util.Date date = new java.util.Date();
// 取本地系统时间:2000-10-27 09:36:58
String currTime = DateFormat.getDateTimeInstance().format(date);
return currTime;// 返回本地系统时间:2000/10/27 09:36:58
}
在项目中,当前系统时间和数据库的时间可能不同步,最好以数据库时间为准。在插入时,SQL里直接用now()
9. 【Java】怎样获取当前系统时间,需要的格式为yyyy-MM-dd HH:mm:ss
SimpleDateFormat
sdf=new
SimpleDateFormat("yyyy-MM-dd
HH:mm:ss");
String
time=
sdf.format(
new
Date());
这个字符串
time已经成为你要的格式了
字符串变date
Date
date=sdf.parse(time);