MyBatis date_format format Time output

Source: Internet
Author: User
Tags month name string format
Reference: http://www.cnblogs.com/yangy608/p/3950095.html

One, in Oracle, when you want to convert the string "2011-09-20 08:30:45" into a date format, we can use the To_date function provided by Oracle.

The SQL statement is:

SELECT to_date (' 2011-09-20 08:30:45 ', ' yyyy-mm-dd hh24:mi:ss ') from dual;

Conversely, you can use the To_char () function to convert dates into strings.

The SQL statement is:

SELECT to_char (sysdate, ' Yyyy-mm-dd hh24:mi:ss ') from dual;

Second, in MySQL, the date_format (date, format) function formats the date value according to the format string.

%M month name (January ... December)
%W Week name (Sunday ... Saturday)
%d The date of the month with English prefixes (1st, 2nd, 3rd, etc.). )
%Y year, number, 4 bit
%y year, number, 2 bit
%a abbreviated weekday name (Sun ... Sat)
Number of days in the month of%d, number (00 ...). 31)
Number of days in%e month, number (0 ... 31)
%m Month, number (01 ... 12)
%c month, number (1 ... 12)
%b Abbreviated month name (Jan ... DEC)
%j Days of the year (001 ... 366)
%H hours (00 ... 23)
%k hours (0 ... 23)
%h hours (01 ... 12)
%I Hours (01 ... 12)
%l hours (1 ... 12)
%i minutes, Numbers (00 ... 59)
%r time, 12 hours (Hh:mm:ss [ap]m)
%T time, 24 hours (HH:MM:SS)
%s seconds (00 ... 59)
%s seconds (00 ... 59)
%p am or PM
%w days in one weeks (0=sunday ... 6=saturday)
%u Week (0 ... 52), here Sunday is the first day of the week
%u Week (0 ... 52), here Monday is the first day of the week
Percent of a text "%".

Convert a string to a date format

SELECT date_format (' 2011-09-20-08:30:45 ',   

Convert date to string format

SELECT Date_format (now (),   

<sql id= "Base_column_list2" >
R.id, r.room_id, R.name, R.option1, R.option2, R.option3, R.option4, R.option5, R.answer,
Date_format (R.etime, '%y-%m-%d%h:%i:%s ') as ETime,<!--there must be an alias here. -
Date_format (R.ctime, '%y-%m-%d%h:%i:%s ') as CTime,
</sql>

<select id= "Getroomguessvobyroomid" parametertype= "Java.lang.Long" resultmap= "BASERESULTMAP2" >
Select <include refid= "Base_column_list2" ></include>
A.nick_name, a.head_img from ' wsp_room_guess ' R left JOIN
Wsp_room m on r.room_id =m.id left JOIN
Wsp_user A on m.user_id = a.id where m.id= #{roomid,jdbctype=bigint}
</select>

the Time field in the <!--entity is timestamp type --

<result column= "ETime" jdbctype= "TIMESTAMP" property= "ETime"/>
<result column= "CTime" jdbctype= "TIMESTAMP" property= "CTime"/>

<!--The Po object Time field that is used for the output is a varchar type, resulting in a direct query when the time appears with. 0 of the exact time, "2017-08-09 14:00:20.0 Situation"-

<result column= "etime" jdbctype= "VARCHAR" property= "ETime"/>
<result Column= "CTime" jdbctype= "VARCHAR" property= "CTime"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.