當前位置:首頁 » 編程語言 » java年月日

java年月日

發布時間: 2022-01-09 14:28:53

A. java如何判斷是否為有效的年月日

年 大於 1900
月 大於0,小於13
日 if(月=1,3,5,7,8,10,12){日大於1小於等於31};
else if{月=4,6,9,11}{日大於1小於等於30};
else if(年是潤年){日大於1小於等於29};
else {日大於1小於等於28}

閏年的判斷公式如下:能被4整除且不能被100整除(year%4==0&&year&&100!=0)

B. java中怎樣輸入年月日

import java.io.*;
public class Date{

public static void main(String [] args)throws NumberFormatException, IOException{
int year = 0;
int month = 0;
int day = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
year = Integer.parseInt(br.readLine());
month = Integer.parseInt(br.readLine());
day = Integer.parseInt(br.readLine());
System.out.println(year + "年" + month + "月" + day + "日");
}

}

說明 :
輸入2008 回車
輸入 5 回車
輸入 30 回車

輸出 2008年5月30日

C. java中年月日怎樣比較大小

如果是Date類型把他轉化成String類型比較,直接用String里的方法
strA.compareTo(strB)就可以 >0 strA的時間在後,<0 相反, =0時候兩個時間相等

D. java 年月日程序

用switch , 按照大小月 和是否閏年來判斷每月的天數
1月大2月小, 1月則為31天 2月是個特殊情況 閏年為29天反之為28天!
思路我已經說了 具體代碼編寫很簡單了

這是判斷為閏年的條件 (year%400==0)||(year%4==0&&year%100!=0) 我寫了段javasscript代碼:
<script>
var year = 2010;
for(var i=1;i<=12;i++){
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
for(var j=1;j<=31;j++){
document.writeln(i+"/"+j);
}
break;
case 2:
//判斷是否為閏年
if((year%4===0&&year%100!==0)||year%400===0){
for(var j=1;j<=29;j++){
document.writeln(i+"/"+j);
}
break;
}else{
for(var j=1;j<=28;j++){
document.writeln(i+"/"+j);
}
break;
}

default:
for(var j=1;j<=30;j++){
document.writeln(i+"/"+j);
}

}
}

</script>

E. java如何獲取當前時間 年月日 時分秒

//得到long類型當前時間

longl=System.currentTimeMillis();

//new日期對

Datedate=newDate(l);

//轉換提日期輸出格式

SimpleDateFormatdateFormat=newSimpleDateFormat("yyyy-MM-

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

(5)java年月日擴展閱讀

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

F. java如何得到年月日。

1、獲取當前的時間

Date date=new Date();//此時date為當前的時間

2、設置時間的格式

Date date=new Date();//此時date為當前的時間

System.out.println(date);

SimpleDateFormat dateFormat=new SimpleDateFormat(「YYYY-MM-dd」);//設置當前時間的格式,為年-月-日

System.out.println(dateFormat.format(date));

SimpleDateFormat dateFormat_min=new SimpleDateFormat(「YYYY-MM-dd HH:mm:ss」);//設置當前時間的格式,為年-月-日 時-分-秒

System.out.println(dateFormat_min.format(date));

(6)java年月日擴展閱讀

java 獲取當前微秒時間:

package com.ffcs.itm;

public class DataSecUtils {

public static void main(String[] args) {

System.out.println(System.currentTimeMillis()); // 毫秒

System.out.println(getmicTime());

System.out.println(System.currentTimeMillis()); // 毫秒

System.out.println(getmicTime());

}

/**

* @return返回微秒

*/

public static Long getmicTime() {

Long cutime = System.currentTimeMillis() * 1000; // 微秒

Long nanoTime = System.nanoTime(); // 納秒

return cutime + (nanoTime - nanoTime / 1000000 * 1000000) / 1000;

}

}

G. Java中如何設置Date對象的年月日

Date
public Date(int year,
int month,
int day)
參數:
year - year 減去 1900,它必須是 0 到 8099 之間的數。(注意,8099 是由 9999 減去 1900 得到的。)
month - 0 到 11 之間的數
day - 1 到 31 之間的數

測試代碼如下:
import java.util.Date;

public class Test {
public static void main(String args[]){
Date date = new Date(2010-1900,1,10);
System.out.println(date);
}
}

運行結果:
Wed Feb 10 00:00:00 CST 2010

希望對你有幫助。。。。。。仍有問題可以HI我。。。。

H. java怎麼獲取當前時間的年月日

Date d = new Date();
int year = d.getYear()+1900;
int month = d.getMonth()+1;
var day = d.getDate();

I. java 怎麼獲取一個時間的年月日

java獲取一個時間的年月日代碼及相關解釋說明參考下面代碼
package;
importjava.util.Calendar;
publicclassTest{
publicstaticvoidmain(String[]args){
Calendarcal=Calendar.getInstance();//使用日歷類
intyear=cal.get(Calendar.YEAR);//獲取年份
intmonth=cal.get(Calendar.MONTH)+1;//獲取月份,因為從0開始的,所以要加1
intday=cal.get(Calendar.DAY_OF_MONTH);//獲取天
System.out.println("結果:"+year+"-"+month+"-"+day);
}
}

J. java只取年月日

"2002-03-25 12:23:22".split(" ")[0]
按照空格分開,取第一個。

熱點內容
筆記本什麼配置能流暢運行cf 發布:2024-09-20 00:14:19 瀏覽:951
實測華為編譯器 發布:2024-09-19 23:50:52 瀏覽:821
linux匯總 發布:2024-09-19 23:46:39 瀏覽:452
阿里雲伺服器環境搭建教程 發布:2024-09-19 23:21:58 瀏覽:837
黃色文件夾圖標 發布:2024-09-19 23:19:22 瀏覽:684
mysql資料庫導出導入 發布:2024-09-19 23:00:47 瀏覽:183
lua腳本精靈 發布:2024-09-19 23:00:41 瀏覽:659
任務欄文件夾圖標 發布:2024-09-19 22:54:25 瀏覽:101
解壓來一波 發布:2024-09-19 22:46:36 瀏覽:933
mysqlpythonubuntu 發布:2024-09-19 22:46:27 瀏覽:501