inputhelper.java

来自「分布式议程管理系统」· Java 代码 · 共 80 行

JAVA
80
字号
/**
 * 
 */
package sysu.agenda.ctrl;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * @author Administrator
 *
 */
public class InputHelper {

	/**
	 * 
	 */
	public InputHelper() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
	
	public Date StingToDate(String str) throws ParseException {
		// Create a date formatter that can parse dates of
		// the form mm-dd-yyyy.
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy");
		// Create a string containing a text date to be parsed.
		// String dateStringToParse = "9-29-2001";
		Date date = bartDateFormat.parse(str);
		return date;
	}
	
	public String DateToString(Date date){
		SimpleDateFormat bartDateFormat = new SimpleDateFormat("MM-dd-yyyy");
		return bartDateFormat.format(date);
	}
	
	/**
	 * static class for Singleton design pattern, instance of InputHelper will
	 * be created when the first time you make a call to
	 * InputHelper.getInstance
	 * 
	 * @author Cyberpet
	 * @see InputHelper#getInstance()
	 */
	static class InputHelperSingletonHolder {
		static InputHelper instance = new InputHelper();
	}

	/**
	 * get the only instance of InputHelper
	 * 
	 * @return InputHelper
	 * @see InputHelper
	 */
	public static InputHelper getInstance() {
		return InputHelperSingletonHolder.instance;
	}
	
	public String trimExtension(String filename) {
		if ((filename != null) && (filename.length() > 0)) {
			int i = filename.lastIndexOf('.');
			if ((i > -1) && (i < (filename.length()))) {
				return filename.substring(0, i);
			}
		}
		return filename;
	}

}

⌨️ 快捷键说明

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