Java Week getWeekName()

Here you can find the source of getWeekName()

Description

get Week Name

License

Open Source License

Declaration

public static String getWeekName() 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {
    private static final String PATTERN = "yyyy-MM-dd";

    public static String getWeekName() {
        return getCurrentTime("yyyy") + getWeekOfYear();
    }//  w w w  .  ja  v a2 s.com

    public static String getCurrentTime() {
        return getCurrentTime(null);
    }

    public static String getCurrentTime(String pattern) {
        return parseDate2String(new Date(), pattern);
    }

    public static String getWeekOfYear() {
        String num = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR) + "";
        return num.length() == 1 ? "0" + num : num;
    }

    public static String parseDate2String(Date date, String pattern) {
        return getSimpleDateFormatInstance(pattern).format(date);
    }

    public static String parseDate2String(Date date) {
        return parseDate2String(date, null);
    }

    private static SimpleDateFormat getSimpleDateFormatInstance(String pattern) {
        return new SimpleDateFormat(pattern == null ? PATTERN : pattern);
    }
}

Related

  1. getWeekDates(int weekOffset)
  2. getWeekFirst(String format)
  3. getWeekFromDate(String dateString)
  4. getWeekId(String date)
  5. getWeekInMonth()
  6. getWeekNumber(String sdate)
  7. getWeekNumberFromDate(String thedate)
  8. getWeekNumByDate(String date)
  9. getWeekNumner(String date)