導航:首頁 > 編程語言 > getdatejava

getdatejava

發布時間:2023-06-10 03:07:41

『壹』 java如何獲取當前時間 年月日 時分秒

//得到long類型當前時間

longl=System.currentTimeMillis();

//new日期對

Datedate=newDate(l);

//轉換提日期輸出格式

SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-

ddHH:mm:ss");System.out.println(dateFormat.format(date));

(1)getdatejava擴展閱讀

package com.ob;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

public class DateTest {

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

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));

System.out.println("秒: " + now.get(Calendar.SECOND));

System.out.println("當前時間毫秒數:" + now.getTimeInMillis());

System.out.println(now.getTime());

Date d = new Date();

System.out.println(d);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateNowStr = sdf.format(d);

System.out.println("格式化後的日期:" + dateNowStr);

String str = "2012-1-13 17:26:33";

//要跟上面sdf定義的格式一樣
Date today = sdf.parse(str);

System.out.println("字元串轉成日期:" + today);
}
}

『貳』 JAVA中怎樣獲取資料庫中查詢出來的日期

如果只是想從資料庫中把日期調出來,可以定義一個日期對象來保存,比如你現在查詢到的結果都保存在Result結果集中,假如其對象為rs,第6列的內容為日期內容,可是使用
java.util.Date d = rs.getDate(6);
來獲得該日期。

如果你想把日期對象導入資料庫中,可以先使用一個String來保存日期,將其保存為一個字元串,然後在進行格式化,例如:
String birthday = "2007-08-21";
temp = new SimpleDateFormat("yyyy-MM-dd").parse(birthday);
java.sql.Date bir = new java.sql.Date(temp.getTime());
然後將bir插入資料庫即可。

『叄』 java中date的獲取以及使用

1、使用new Date()獲取當前日期,new Date().getTime()獲取當前毫秒數

2、計算公式,等於獲取的當前日期減去或者加上一天的毫秒數。一天的毫秒數的計算公式:24小時*60分鍾*60秒*1000毫秒,也是86400000毫秒。

舉例:

Date curDate = new Date();

var preDate = new Date(curDate.getTime() - 24*60*60*1000); //前一天

var nextDate = new Date(curDate.getTime() + 24*60*60*1000); //後一天

以下圖片使用後台輸出表示。

(3)getdatejava擴展閱讀

var myDate = new Date();

myDate.getYear(); //獲取當前年份(2位)

myDate.getFullYear(); //獲取完整的年份(4位,1970-????)

myDate.getMonth(); //獲取當前月份(0-11,0代表1月)

myDate.getDate(); //獲取當前日(1-31)

myDate.getDay(); //獲取當前星期X(0-6,0代表星期天)

myDate.getTime(); //獲取當前時間緩友(從1970.1.1開始的毫秒數)

myDate.getHours(); //獲取當前小時數(0-23)

myDate.getMinutes(); //獲取當前分鍾數(0-59)

myDate.getSeconds(); //獲取當前秒數(0-59)

myDate.getMilliseconds(); //獲取當前毫秒數(0-999)

myDate.toLocaleDateString(); //獲取當前日期

var mytime=myDate.toLocaleTimeString(); //獲取當前時間

myDate.toLocaleString( ); //獲取日襪隱期與時間

Date.prototype.isLeapYear 判斷閏年

Date.prototype.Format 日期格式化

Date.prototype.DateAdd 日期計算

Date.prototype.DateDiff 比較日期差

Date.prototype.toString 日期轉字元串

Date.prototype.toArray 日期分割為擾好槐數組

Date.prototype.DatePart 取日期的部分信息

Date.prototype.MaxDayOfDate 取日期所在月的最大天數

Date.prototype.WeekNumOfYear 判斷日期所在年的第幾周

StringToDate 字元串轉日期型

IsValidDate 驗證日期有效性

CheckDateTime 完整日期時間檢查

daysBetween 日期天數差

閱讀全文

與getdatejava相關的資料

熱點內容
電腦文件夾分列 瀏覽:577
歐美最黃最爆的電影:歐美最火爆的電影推薦 瀏覽:844
韓劇電影愛情:浪漫與現實的交融 瀏覽:695
印度誤殺女主事件引發的社會反思與改進措施 瀏覽:214
文件夾公司 瀏覽:894
建設銀行使用的什麼伺服器 瀏覽:107
ftp創建文件java 瀏覽:462
王者大仙杯獎勵文件夾 瀏覽:854
pdf2345 瀏覽:7
歐美大尺度床戲電影:解析情感與藝術的碰撞 瀏覽:470
如何查看伺服器io 瀏覽:307
神鼠電影:用滑鼠點亮未來的冒險故事 瀏覽:393
大陸初啟航電影第3集:走進角色關系的細微波動 瀏覽:791
金基延演過的電影:魅力演技與思考人生的力量 瀏覽:704
安卓如何同時登錄二個qq 瀏覽:131
史泰龍全部電影:傳奇咆哮的動作巨星 瀏覽:332