⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timestamp.java

📁 学校的学生和工人管理系统 可以完成增删改查的功能
💻 JAVA
字号:
/*
 * 创建日期 2005-9-21
 *
 * TODO 要更改此生成的文件的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
package cn.itcareers.lxh.exercise.util;

/**
 * @author 白涛
 *
 * TODO 要更改此生成的类型注释的模板,请转至
 * 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * @author Administrator
 * 
 * TODO 要更改此生成的类型注释的模板,请转至 窗口 - 首选项 - Java - 代码样式 - 代码模板
 */
public class TimeStamp {
	private Calendar calendar = null;

	private int year;

	private int month;

	private int day;

	private int hour;

	private int minute;

	private int second;

	private int millisecond;

	/**
	 * 初始化TimeStamp()类
	 *
	 */
	public TimeStamp() {
		calendar = new GregorianCalendar();
		this.set();
	}

	/**
	 * 初始化类中属性
	 *  
	 */
	private void set() {
		this.year = calendar.get(Calendar.YEAR);
		this.month = calendar.get(Calendar.MONTH) + 1;
		this.day = calendar.get(Calendar.DAY_OF_MONTH);
		this.hour = calendar.get(Calendar.HOUR_OF_DAY);
		this.minute = calendar.get(Calendar.MINUTE);
		this.second = calendar.get(Calendar.SECOND);
		this.millisecond = calendar.get(Calendar.MILLISECOND);
	}

	/**
	 * 得到时间序列号
	 * 
	 * @return
	 */
	public String getTimeNumber() {
		return this.change(Integer.toString(this.year))
				+ this.change(Integer.toString(this.month))
				+ this.change(Integer.toString(this.day))
				+ this.change(Integer.toString(this.hour))
				+ this.change(Integer.toString(this.minute))
				+ this.change(Integer.toString(this.second))
				+ this.changeMill(Integer.toString(this.millisecond));
	}

	/**
	 * 以下方法用于完善时间数
	 * 
	 * @param temp
	 * @return
	 */
	private String change(String temp) {
		if (temp.length() < 2) {
			return "0" + temp;
		} else {
			return temp;
		}
	}

	/**
	 * 以下方法用于完善毫秒数
	 * 
	 * @param temp
	 * @return
	 */
	private String changeMill(String temp) {
		while (temp.length() < 3)
			temp = "0" + temp;
		return temp;
	}

	/**
	 * 以下方法用于取得当前时间
	 * 
	 * @return
	 */
	public String getDate() {
		return this.change(Integer.toString(this.year)) + "年"
				+ this.change(Integer.toString(this.month)) + "月"
				+ this.change(Integer.toString(this.day)) + "日";
	}

	/**
	 * 以下方法用于取得时间戳
	 * 
	 * @return
	 */
	public String getTimeStamp() {
		return this.change(Integer.toString(this.year)) + "-"
				+ this.change(Integer.toString(this.month)) + "-"
				+ this.change(Integer.toString(this.day)) + " "
				+ this.change(Integer.toString(this.hour)) + ":"
				+ this.change(Integer.toString(this.minute)) + ":"
				+ this.change(Integer.toString(this.second));
	}
}

⌨️ 快捷键说明

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