java String.Format() ÈÕÆÚ¸ñʽÓ÷¨
ÔÎÄ´«ËÍÃÅ£ºhttp://solodu.javaeye.com/blog/454546
JDK1.5ÖУ¬StringÀàÐÂÔöÁËÒ»¸öºÜÓÐÓõľ²Ì¬·½·¨String.format():ÏÖÓÐÒ»¸öʱ¼ä'20090903'Ҫת»¯³ÉÖ¸¶¨Ê±¼äµÄjava.util.Date¸ñʽ
private Date getStartGregorianTime(String date) {
Date d_date = DateUtil.parseDate(date);
int year = new Integer(String.format("%tY", d_date));
int month = new Integer(String.format("%tm", d_date));
int day = new Integer(String.format("%td", d_date));
return new GregorianCalendar(year, month-1, day, 0, 0, 0).getTime();
}
private Date getEndGregorianTime(String date) {
Date d_date = DateUtil.parseDate(date);
int year = new Integer(String.format("%tY", d_date));
int month = new Integer(String.format("%tm", d_date));
int day = new Integer(String.format("%td", d_date));
return new GregorianCalendar(year, month-1, day, 23, 59, 59).getTime();
}
ÒÔÏÂΪString format()ÖвÎÊýµÄ¶¨Òå:
ÈÕÆÚ/ʱ¼äת»»
ÒÔÏÂÈÕÆÚºÍʱ¼äת»»µÄºó׺×Ö·ûÊÇΪ 't' ºÍ 'T' ת»»¶¨ÒåµÄ¡£ÕâЩÀàÐÍÏàËÆÓÚµ«²»ÍêÈ«µÈͬÓÚÄÇЩÓÉ GNU date ºÍ POSIX strftime(3c) ¶¨ÒåµÄÀàÐÍ¡£ÌṩÆäËûת»»ÀàÐÍÊÇΪÁË·ÃÎÊÌض¨ÓÚ Java µÄ¹¦ÄÜ£¨È罫 'L' ÓÃ×÷ÃëÖеĺÁÃ룩¡£
ÒÔÏÂת»»×Ö·ûÓÃÀ´¸ñʽ»¯Ê±¼ä£º
'H' 24 СʱÖƵÄСʱ£¬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄÁ½Î»Êý£¬¼´ 00 - 23¡£
'I' 12 СʱÖƵÄСʱ£¬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄÁ½Î»Êý£¬¼´ 01 - 12¡£
'k' 24 СʱÖƵÄСʱ£¬¼´ 0 - 23¡£
'l' 12 СʱÖƵÄСʱ£¬¼´ 1 - 12¡£
'M' СʱÖеķÖÖÓ£¬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄÁ½Î»Êý£¬¼´ 00 - 59¡£
'S' ·ÖÖÓÖеÄÃ룬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄÁ½Î»Êý£¬¼´ 00 - 60 £¨"60" ÊÇÖ§³ÖÈòÃëËùÐèµÄÒ»¸öÌØÊâÖµ£©¡£
'L' ÃëÖеĺÁÃ룬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄÈýλÊý£¬¼´ 000 - 999¡£
'N' ÃëÖеĺÁ΢Ã룬±»¸ñʽ»¯Îª±ØҪʱ´øÇ°µ¼ÁãµÄ¾ÅλÊý£¬¼´ 000000000 - 999999999¡£
'p' Ìض¨ÓÚÓïÑÔ»·¾³µÄ ÉÏÎç»òÏÂÎç ±ê¼ÇÒÔСдÐÎʽ±íʾ£¬ÀýÈç "am" »ò "pm"¡
Ïà¹ØÎĵµ£º
Javaѧϰ´ÓÈëÃŵ½¾«Í¨
Ò»¡¢ JDK (Java Development Kit)
JDKÊÇÕû¸öJavaµÄºËÐÄ£¬°üÀ¨ÁËJavaÔËÐл·¾³£¨Java Runtime Envirnment£©£¬Ò»¶ÑJava¹¤¾ßºÍJava»ù´¡µÄÀà¿â(rt.jar)¡£²»ÂÛʲôJavaÓ¦Ó÷þÎñÆ÷ʵÖʶ¼ÊÇÄÚÖÃÁËij¸ö°æ±¾µÄJDK¡£Òò´ËÕÆÎÕJDKÊÇѧºÃJavaµÄµÚÒ»²½¡£×îÖ÷Á÷µÄJ ......
µÇ¼ÑéÖ¤£¬µ±Óû§ÃûΪabc£¬ÃÜÂëΪ123ʱ·µ»Øͨ¹ý£¬·ñÔòΪµÇ¼ʧ°Ü£¬ÈôÖ»ÊäÈëÁËÆäÖÐÒ»ÏÔò·µ»Ø²ÎÊý²»ÕýÈ·¡£
´úÂëÈçÏ£º
//µÇ¼ÑéÖ¤·¶Àý ——Ò»¸ö±ê×¼µÄ³ÌÐòÉè¼Æģʽ
class Login
{
private S ......
Èç¹ûÏëÈÃËùÓÐÓû§share:
emacs -nw /etc/profile
È»ºóÔÚδβ¼ÓÈë
#set java environment
set JAVA_HOME=/usr/java/jdk1.5.0_16
set PATH=.:$JAVA_HOME/bin:$PATH
export PATH JAVA_HOME
Èç¹û½öµ±Ç°Óû§Ê¹Óãº
°ÑÉÏÃæµÄ¼ÓÈëÓû§Ä¿Â¼ÏµÄ.bash_profile»ò.bash-rc
È»ºóÔËÐÐsource /etc/profileÉúЧ ......
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import au.com.bytecode.opencsv.CSVWriter;
public class CsvDemo {
public static void main(String[] args) throws IOException {
  ......