熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

JAVA裡的日期處理

2022-06-13   來源: Java核心技術 

  package mechendddate

  import javatextParseExceptionimport javatextSimpleDateFormatimport javautilCalendarimport javautilDate

  import javaxswingtextStyleContextSmallAttributeSet

  public class TestDate {

  public static void main(String[] args) throws ParseException {

  Date now = new Date()//取運行的時間Systemoutprintln(now)

  long s = SystemcurrentTimeMillis()//取當前據 所過的毫秒數for(int i = i <= i++) {

  } long e = SystemcurrentTimeMillis()Systemoutprintln(es)

  SimpleDateFormat sdf = new SimpleDateFormat(yyyymmdd hhmmss//將Date轉換為特定的格式String str = sdfformat(now)Systemoutprintln(str)

  String ss = Date d = sdfparse(ss)//將特定格式日期轉換為Date Systemoutprintln(d)

  Calendar n = CalendargetInstance()//獲取它的實例注意是抽象類不能用new Systemoutprintln(n)nset( //設定日期//      int today = ngetTime()getDay()Systemoutprintln(ngetTime())int dd = nDAY_OF_WEEK//是該周的第幾天Systemoutprintln(dd)}

  }


From:http://tw.wingwit.com/Article/program/Java/hx/201311/26402.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.