2012年11月27日 星期二

Oracle date format


參考:http://www.oradev.com/oracle_date_format.jsp

Oracle date format

With the functions to_char and to_date, a date format can be used. Example:
select to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
will return something like: 24/03/2006 14:36:43

Here is a list of all the formats that can be used:
Format maskDescription
CCCentury
SCCCentury BC prefixed with -
YYYYYear with 4 numbers
SYYYYear BC prefixed with -
IYYYISO Year with 4 numbers
YYYear with 2 numbers
RRYear with 2 numbers with Y2k compatibility
YEARYear in characters
SYEARYear in characters, BC prefixed with -
BCBC/AD Indicator *
QQuarter in numbers (1,2,3,4)
MMMonth of year 01, 02...12
MONTHMonth in characters (i.e. January)
MONJAN, FEB
WWWeeknumber (i.e. 1)
WWeeknumber of the month (i.e. 5)
IWWeeknumber of the year in ISO standard.
DDDDay of year in numbers (i.e. 365)
DDDay of the month in numbers (i.e. 28)
DDay of week in numbers(i.e. 7)
DAYDay of the week in characters (i.e. Monday)
FMDAYDay of the week in characters (i.e. Monday)
DYDay of the week in short character description (i.e. SUN)
JJulian Day (number of days since January 1 4713 BC, where January 1 4713 BC is 1 in Oracle)
HHHournumber of the day (1-12)
HH12Hournumber of the day (1-12)
HH24Hournumber of the day with 24Hours notation (0-23)
AMAM or PM
PMAM or PM
MINumber of minutes (i.e. 59)
SSNumber of seconds (i.e. 59)
SSSSSNumber of seconds this day.
DSShort date format. Depends on NLS-settings. Use only with timestamp.
DLLong date format. Depends on NLS-settings. Use only with timestamp.
EAbbreviated era name. Valid only for calendars: Japanese Imperial, ROC Official and Thai Buddha.. (Input-only)
EEThe full era name
FFThe fractional seconds. Use with timestamp.
FF1..FF9The fractional seconds. Use with timestamp. The digit controls the number of decimal digits used for fractional seconds.
FMFill Mode: suppresses blianks in output from conversion
FXFormat Exact: requires exact pattern matching between data and format model.
IYY or IY or Ithe last 3,2,1 digits of the ISO standard year. Output only
RMThe Roman numeral representation of the month (I .. XII)
RRThe last 2 digits of the year.
RRRRThe last 2 digits of the year when used for output. Accepts fout-digit years when used for input.
SCCCentury. BC dates are prefixed with a minus.
CCCentury
SPSpelled format. Can appear of the end of a number element. The result is always in english. For example month 10 in format MMSP returns "ten"
SPTHSpelled and ordinal format; 1 results in first.
THConverts a number to it's ordinal format. For example 1 becoms 1st.
TSShort time format. Depends on NLS-settings. Use only with timestamp.
TZDAbbreviated time zone name. ie PST.
TZHTime zone hour displacement.
TZMTime zone minute displacement.
TZRTime zone region
XLocal radix character. In america this is a period (.)

2012年11月15日 星期四

[JAVA] DATE 和STRING的轉換


Calendar today = new GregorianCalendar();

DateFormate dateFormat=new SimpleDateFormat("yyyyMMdd");

date=dateFormat.format(today);


Java字串轉日期範例
1.//欲轉換的日期字串
2.String dateString = "20010-03-02 20:25:58";
3.//設定日期格式
4.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
5.//進行轉換
6.Date date = sdf.parse(dateString);
7.System.out.println(date);

http://cooking-java.blogspot.tw/2010/03/java-string-to-date.html


Java 日期轉字串範列
1.//目前時間
2.Date date = new Date();
3.//設定日期格式
4.SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
5.//進行轉換
6.String dateString = sdf.format(date);
7.System.out.println(dateString);
http://cooking-java.blogspot.tw/2010/03/java-date-to-string.html


JAVA年要用yyyy表示


http://stackoverflow.com/questions/3583384/converting-a-calendar-object-into-a-string-in-java-with-format-yyyy-mm-dd-hhmm

http://weick.iteye.com/blog/227707