get current wee

Posted applekingghfhfhbr

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了get current wee相关的知识,希望对你有一定的参考价值。

package com.sangame.uc.front.web.controller.front;

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

/**
* Created by on 2017/4/17.
*/
public class DateUtils {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

public static void main(String args[]){
System.out.println(getCurrentMonday());
System.out.println(getPreviousSunday());
System.out.println(getMinMonthDate("2017-04-17"));
System.out.println(getMaxMonthDate("2017-04-17"));
}
// 获得本周一与当前日期相差的天数
public static int getMondayPlus() {
Calendar cd = Calendar.getInstance();
int dayOfWeek = cd.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == 1) {
return -6;
} else {
return 2 - dayOfWeek;
}
}

// 获得当前周- 周一的日期
public static String getCurrentMonday() {
int mondayPlus = getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}


// 获得当前周- 周日 的日期
public static String getPreviousSunday() {
int mondayPlus = getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus +6);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
String preMonday = df.format(monday);
return preMonday;
}
// 获得当前月--开始日期
public static String getMinMonthDate(String date) {
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(dateFormat.parse(date));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
return dateFormat.format(calendar.getTime());
} catch (java.text.ParseException e) {
e.printStackTrace();
}
return null;
}

// 获得当前月--结束日期
public static String getMaxMonthDate(String date){
Calendar calendar = Calendar.getInstance();
try {
calendar.setTime(dateFormat.parse(date));
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
return dateFormat.format(calendar.getTime());
} catch (java.text.ParseException e) {
e.printStackTrace();
}
return null;
}
}

以上是关于get current wee的主要内容,如果未能解决你的问题,请参考以下文章

get current wee

wordpress 插件 -> 调用未定义的函数 wp_get_current_user()

python- flask current_app详解,与 current_app._get_current_object()的区别以及异步发送邮件实例

javascript get_current_params_object.js

python form-get-current-user.py

unw_get_proc_name -- get name of current procedure