JAVA中用代码写年月日,年月日代码怎么写

java 编程中显示日期和时间的代码

可以直接通过jdk基本方法,获取到当前的时间

成都创新互联从2013年创立,是专业互联网技术服务公司,拥有项目做网站、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元霸州做网站,已为上家服务,为霸州各地企业和个人服务,联系电话:028-86922220

Date date= new Date();//创建一个时间对象,获取到当前的时间

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置时间显示格式

String str = sdf.format(date);//将当前时间格式化为需要的类型

System.out.println(str);//输出结果

结果为:2015-11-06 13:53:54(实时)。

java 怎么获取一个时间的年月日

java获取一个时间的年月日代码及相关解释说明参考下面代码

package zhidao;

import java.util.Calendar;

public class Test {

public static void main(String[] args) {

Calendar cal=Calendar.getInstance();//使用日历类

int year=cal.get(Calendar.YEAR);//获取年份

int month=cal.get(Calendar.MONTH)+1;//获取月份,因为从0开始的,所以要加1

int day=cal.get(Calendar.DAY_OF_MONTH);//获取天

System.out.println("结果:"+year+"-"+month+"-"+day);

}

}

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日

java中的年月日简单编程

将这段代码拷贝到UseBirthday类中和你的比较一下看看

public class UseBirthday {

public static void main(String[] args) {

Birthday a=new Birthday(2000,1,1);

a.GetBirthday();

a.Birthday(2008,5,12);

a.GetBirthday();

}

}

class Birthday {

private int Year, Month, Day;

Birthday(){

Year=2000;

Month=1;

Day=1;

}

Birthday(int y,int m,int d) {

Year = y;

Month = m;

Day = d;

}

public void Birthday(int y,int m,int d){

Year = y;

Month = m;

Day = d;

}

int Gety() {

return Year;

}

int Getm() {

return Month;

}

int Getd() {

return Day;

}

void GetBirthday() {

System.out.println(Gety() + "年" + Getm() + "月" + Getd() + "日");

}

}

Java编写程序,输入年份,输出本年度各月份日历

写了个简明的,

import java.util.Calendar;

import java.util.Scanner;

public class Test {

static public void main(String 参数[]){

Calendar c = Calendar.getInstance();

Scanner sc = new Scanner(System.in);

System.out.println("请输入年份:");

int year= sc.nextInt();

c.set(Calendar.YEAR, year);

c.set(Calendar.MONTH, Calendar.JANUARY);

c.set(Calendar.DAY_OF_MONTH, 1);

while(c.get(Calendar.YEAR)==year){

int wday=c.get(Calendar.DAY_OF_WEEK);

int mday=c.get(Calendar.DAY_OF_MONTH);

if(mday==1){

System.out.println("\n日\t一\t二\t三\t四\t五\t六\t第"+(c.get(Calendar.MONTH)+1)+"月");

System.out.println("---------------------------------------------------");

for(int i=0;iwday-1;i++) System.out.print(" \t");

}

System.out.print(mday+"\t");

if(wday==7) System.out.println();

c.add(Calendar.DAY_OF_YEAR, 1);

}

}

}

=======

请输入年份:

2012

日 一 二 三 四 五 六 第1月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

日 一 二 三 四 五 六 第2月

---------------------------------------------------

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29

日 一 二 三 四 五 六 第3月

---------------------------------------------------

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

日 一 二 三 四 五 六 第4月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30

日 一 二 三 四 五 六 第5月

---------------------------------------------------

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30 31

日 一 二 三 四 五 六 第6月

---------------------------------------------------

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

日 一 二 三 四 五 六 第7月

---------------------------------------------------

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

日 一 二 三 四 五 六 第8月

---------------------------------------------------

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30 31

日 一 二 三 四 五 六 第9月

---------------------------------------------------

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30

日 一 二 三 四 五 六 第10月

---------------------------------------------------

1 2 3 4 5 6

7 8 9 10 11 12 13

14 15 16 17 18 19 20

21 22 23 24 25 26 27

28 29 30 31

日 一 二 三 四 五 六 第11月

---------------------------------------------------

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30

日 一 二 三 四 五 六 第12月

---------------------------------------------------

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

如何用JAVA写日历?

按照你的要求编写的Java日历验证程序如下

UI.java

import java.util.Scanner;

public class UI {

static Scanner sc=new Scanner(System.in);

public static int askInt(String s){

System.out.print(s);

return sc.nextInt();

}

public static void println(String s){

System.out.println(s);

}

}

EE.java

public class EE {

public void validateDateCore(){

int year =UI.askInt("Enter the year: ");

int month=UI.askInt("Enter the month: ");

int day=UI.askInt("Enter the day: ");

if(year  1){

UI.println("The year is not a valid number.");

return;

}

if(month1 || month12){

UI.println("The month is not a valid number.");

return;

}

int monthDay=0;

switch(month){

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:monthDay=31;break;

case 4:

case 6:

case 9:

case 11:monthDay=30;break;

case 2:

if((year%4==0  year%100!=0) || year%400==0){

monthDay=29;

}else{

monthDay=28;

}

break;

}

if(day1 || daymonthDay){

UI.println("The day is not a valid number.");

return;

}else{

UI.println("It is "+day+"/"+month+"/"+year+".");

}

}

public static void main(String[] args) {

new EE().validateDateCore();

}

}

运行结果

网页名称:JAVA中用代码写年月日,年月日代码怎么写
分享链接:https://www.cdcxhl.com/article26/dsicjjg.html

成都网站建设公司_创新互联,为您提供全网营销推广关键词优化服务器托管手机网站建设域名注册虚拟主机

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计