[轉][Java] Date 格式化

來源:互聯網
上載者:User

標籤:ring   情況   get   framework   import   simple   orm   文法   col   

import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;import java.text.SimpleDateFormat;import java.util.Calendar;public class test2 {    public static void main(String[] args){        ApplicationContext context = new ClassPathXmlApplicationContext(                new String[]{ "dispatcher-servlet.xml" });        Calendar calendar = context.getBean("calendar",Calendar.class);        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        System.out.println(format.format(calendar.getTime()));    }}
yyyy:年  MM:月  dd:日  hh:1~12小時制(1-12)  HH:24小時制(0-23)  mm:分  ss:秒  S:毫秒  E:星期幾  D:一年中的第幾天  F:一月中的第幾個星期(會把這個月總共過的天數除以7)  w:一年中的第幾個星期  W:一月中的第幾星期(會根據實際情況來算)  a:上下午標識  k:和HH差不多,表示一天24小時制(1-24)。  K:和hh差不多,表示一天12小時制(0-11)。  z:表示時區 

 嘗試了一下, 星期 使用的尾部加 E (不能小寫),HH 、MM、dd、mm、ss 同C# 文法,只是 C# 中星期幾是 dddd 表示,並且可以使用 ffff 來格式化毫秒數,而 java 不支援毫秒的格式化。

SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d H:m:s E");

 

[轉][Java] Date 格式化

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.