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

📄 dateformats.java

📁 非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应用程序更漂亮更易操作。 官网:www.zkoss.org
💻 JAVA
字号:
/* DateFormats.java{{IS_NOTE	Purpose: 	Description: 	History:	91/01/17 15:22:22, Create, Tom M. Yeh.}}IS_NOTECopyright (C) 2001 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.text;import java.util.Locale;import java.util.Date;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.text.ParseException;import org.zkoss.util.Locales;/** * DateFormat relevant utilities. * * @author tomyeh */public class DateFormats {	/**	 * Parses a string to a date.	 * It is smart enough to know whether to use DateFormat.getDateInstance	 * and DateFormat.getDateTimeInstance.	 * It also uses {@link Locales#getCurrent}.	 */	public static final Date parse(String s)	throws ParseException {		final Locale locale = Locales.getCurrent();				if (s.indexOf(':') < 0) { //date only			final DateFormat df =				DateFormat.getDateInstance(DateFormat.DEFAULT, locale);			return df.parse(s);		} else {			synchronized (TO_STRING_FORMAT) {				try {					return TO_STRING_FORMAT.parse(s);				} catch (ParseException ex) { //ignore it				}			}			final DateFormat df =				DateFormat.getDateTimeInstance(					DateFormat.DEFAULT, DateFormat.DEFAULT, locale);			return df.parse(s);		}	}	/** The date formatter for generating Date.toString().	 * To use it, remember to synchronized(TO_STRING_FORMAT)	 */	private static final SimpleDateFormat TO_STRING_FORMAT =		new SimpleDateFormat(					"EEE MMM dd HH:mm:ss zzz yyyy", Locale.US);	/** Formats a Date object based on the current Locale.	 *	 * @param dateOnly indicates whether to show only date; false to show	 * both date and time	 */	public static final String format(Date d, boolean dateOnly) {		Locale locale = Locales.getCurrent();		if (dateOnly) {			DateFormat df =				DateFormat.getDateInstance(DateFormat.DEFAULT, locale);			return df.format(d);		} else {			DateFormat df =				DateFormat.getDateTimeInstance(					DateFormat.DEFAULT, DateFormat.DEFAULT, locale);			return df.format(d);		}	}}

⌨️ 快捷键说明

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