pubdate.java

来自「这个程序是花了好几十万请人开发的」· Java 代码 · 共 122 行

JAVA
122 行
字号

package javabean;

//获取系统当前时间的类
import java.util.*;
public class PubDate 
{
	int year,month,date,hour,minute,second,pubdate;
	String week;
	Calendar calendar=null;
	public PubDate()
	{
		calendar=Calendar.getInstance();
		Date time=new Date();
		calendar.setTime(time);
	}
	
	public int getYear()
	{
		return calendar.get(Calendar.YEAR);
	}
	
	public String getMonth()
	{
		int m=1+calendar.get(Calendar.MONTH);
		String months[]={"1","2","3","4","5","6","7","8","9","10","11","12"};
		if(m>12)
			return "0";
		if(months[m-1].length()==1)
			months[m-1]="0"+months[m-1];
		return months[m-1];
	}

	public String getStringDay()
	{
		String Day=String.valueOf(calendar.get(Calendar.DATE));
		if(Day.length()==1)
		{
			Day="0"+Day;
		}
		return Day;
	}
	
	public int getDay()
	{
		return calendar.get(Calendar.DATE);
	}
	
	public int getHour()
	{
		return calendar.get(Calendar.HOUR_OF_DAY);
	}
	
	public int getMinute()
	{
		return calendar.get(Calendar.MINUTE);
	}
	
	public int getSecond()
	{
		return calendar.get(Calendar.SECOND);
	}
	
	public String getPubdate()
	{
		return (this.getYear()+"-"+this.getMonth()+"-"+this.getDay()+"  "+
		this.getHour()+":"+this.getMinute()+":"+this.getSecond());
	}
	
	public  String getDate()
	{
		return (this.getYear()+"-"+this.getMonth()+"-"+this.getDay());
	}

	public String getshortPubdate()
	{
		return (this.getYear()+"-"+this.getMonth()+"-"+this.getStringDay());
	}
	
	public  String getCHDate()
	{
		return (this.getYear()+"年"+this.getMonth()+"月"+this.getDay()+"日");
	}
	
	public String getWeek()
	  {
	   switch(Calendar.DATE)
	   {
		case 0: week="星期日";
		case 1: week="星期一";
		case 2: week="星期二";
		case 3: week="星期三";
		case 4: week="星期四";
		case 5: week="星期五";
		case 6: week="星期六";
	   }
	   return week;
	  }
	  
	public String showmessage()
	{
		String message="";
		if(calendar.get(Calendar.HOUR_OF_DAY)>=1&&calendar.get(Calendar.HOUR_OF_DAY)<=11)
		{
			message="上午好!";
		}
		if(calendar.get(Calendar.HOUR_OF_DAY)>11&&calendar.get(Calendar.HOUR_OF_DAY)<=13)
		{
			message="中午好!";
		}
		if(calendar.get(Calendar.HOUR_OF_DAY)>13&&calendar.get(Calendar.HOUR_OF_DAY)<=18)
		{
			message="下午好!";
		}
		if(calendar.get(Calendar.HOUR_OF_DAY)>18&&calendar.get(Calendar.HOUR_OF_DAY)<=24)
		{
			message="晚上好!";
		}
		return message;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?