包含date格式java的词条

博主:adminadmin 2022-12-22 19:00:11 51

今天给各位分享date格式java的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java中Date对象的格式问题

mysql中sql这么写

SELECT DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%e'), INTERVAL -6 DAY);//当天日期减6天

java中这么写

public static void main (String args[]) throws ParseException{

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");

Date  d = df.parse(df.format(new Date()));     

Calendar cal=Calendar.getInstance();

cal.setTime(d);

cal.add(Calendar.DATE, -6);  //当天日期减6天

System.out.println(df.format(cal.getTime()));

}

Java如何获取Date类型且格式为yyyy-mm-dd的日期数据?

@return返回长时间格式 yyyy-MM-dd HH:mm:ss

*/  public static Date getSqlDate() {

Date sqlDate = new java.sql.Date(new Date().getTime());

return sqlDate;  }  

/**

* 获取现在时间

*

* @return返回长时间格式 yyyy-MM-dd HH:mm:ss

*/  public static Date getNowDate() {

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(currentTime);

ParsePosition pos = new ParsePosition(8);

Date currentTime_2 = formatter.parse(dateString, pos);

return currentTime_2;  }

Java Date格式问题

楼上的都看不懂楼主的问题?要转换成”yyyy-MM-dd”的Date,只能来回转换,先把Date转换成”yyyy-MM-dd”的String,再转化过来

Date currentTime = new Date();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

String dateString = formatter.format(currentTime);

Date currentTime_2 = formatter.parse(dateString);

return currentTime_2;

java Date类型。

Data类型是日期类型,通常是为了获取某些特定的日期或者转换日期的格式为字符串。举例:

Date date = new Date();//定义一个当前日期,此时输出就是日期类型

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//创建格式日期类型

String str = sdf.format(date);//对创建的日期进行格式化输出。此时输出就是字符串日期类型

输出结果:2015--6-30 19:17:32。

如何将JAVA DATE类型的日期 转换成指定格式类型的 (如:YYYY-MM-DD) 的 DATE类型数据?

Date类型并没有格式,只有转换成String格式的时候让格式化显示。

new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")format(new Date());

Calendar calendar = Calendar.getInstance();

int year = Integer.parseInt(datetime.substring(0,4));

int month = Integer.parseInt(datetime.substring(5,7));

int date = Integer.parseInt(datetime.substring(8,10));

int hour = Integer.parseInt(datetime.substring(11,13));

int minute = Integer.parseInt(datetime.substring(14,16));

//int second = Integer.parseInt(datetime.substring(17,19));

if(calendar.get(Calendar.YEAR)year){

int y = calendar.get(Calendar.YEAR)-year;

扩展资料:

Date类可以在java.util包中找到,用一个long类型的值表示一个指定的时刻。它的一个有用的构造函数是Date(),创建一个表示创建时刻的对象。getTime()方法返回Date对象的long值。

import java.util.*;

public class Now {

public static void main(String[] args) {

Date now = new Date();

long nowLong = now.getTime();

System.out.println("Value is " + nowLong);

参考资料来源:百度百科-java日期函数

date格式java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、date格式java的信息别忘了在本站进行查找喔。

The End

发布于:2022-12-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。