zoukankan      html  css  js  c++  java
  • 日期类及其格式化程序(在实际中的运用)

    一、在日常中会大量使用日期类,取出日期的操作

    形式一:2012-11-07

    形式二:2012-11-0707:08:26.236

    形式三:2012年11月07日

    形式四:2012年11月07日 07时08分26秒236毫秒

    package org.lxh.dateformatdemo; 

    import java.text.SimpleDateFormat;

    import java.util.Date; 

    public class DateTime {

           private SimpleDateFormat sdf = null;

           public String getDate() {//2009-03-02

                  this.sdf = new SimpleDateFormat("yyyy-MM-dd");

                  String str = this.sdf.format(new Date());

                  return str;

           }

           public String getDateTime() {// 2009-03-02 16:19:34.123

                  this.sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");

                  String str = this.sdf.format(new Date());

                  return str;

           }

           public String getDateComplete() {//2009年03月02日

                  this.sdf = new SimpleDateFormat("yyyy年MM月dd日");

                  String str = this.sdf.format(new Date());

                  return str;

           }

           public String getDateTimeComplete() {//2009年03月02日16时19分34秒123毫秒

                  this.sdf = new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒SSS毫秒");

                  String str = this.sdf.format(new Date());

                  return str;

           }

           public String getDateTimeStamp(){

                  this.sdf = new SimpleDateFormat("yyyyMMddhhmmssSSS");

                  String str = this.sdf.format(new Date());

                  return str;

           }

           public static void main(String args[]) {

                  DateTime dt = new DateTime() ;

                  System.out.println(dt.getDateTimeComplete());

                  System.out.println(dt.getDateTime());

                  System.out.println(dt.getDateTimeStamp());

           }

    }

  • 相关阅读:
    spring 任务调度quartz
    java增强型for循环
    DateTimeFormat
    Java的同步和异步
    HTTP Status 400,400 (Bad Request)
    com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '2.34435678977654336E17' in column '3' is outside valid range for the datatype INTEGER.
    Servlet.service() for servlet [appServlet] in context with path [/item] threw exception [Request processing failed
    mysql调优
    Windows nexus 启动失败
    NFS客户端访问行为相关的几个参数解释
  • 原文地址:https://www.cnblogs.com/jiechn/p/2768912.html
Copyright © 2011-2022 走看看