本文整理汇总了Java中org.joda.time.DateTime.getDayOfWeek方法的典型用法代码示例。如果您正苦于以下问题:Java DateTime.getDayOfWeek方法的具体用法?Java DateTime.getDayOfWeek怎么用?Java DateTime.getDayOfWeek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.joda.time.DateTime
的用法示例。
在下文中一共展示了DateTime.getDayOfWeek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: DayAdapter
import org.joda.time.DateTime; //导入方法依赖的package包/类
public DayAdapter(int calendarHeight, DateTime startDateTime, GetViewHelper getViewHelper, DateTime selectDateTime) {
this.calendarHeight = calendarHeight;
this.getViewHelper = getViewHelper;
this.selectDateTime = selectDateTime;
dateTimes = new ArrayList<>();
final int daysOfMonth = startDateTime.dayOfMonth().getMaximumValue();
int firstDayOfWeek = startDateTime.getDayOfWeek() % DAYS_OF_WEEK;
for (int i = firstDayOfWeek; i >= 1; i--) {
dateTimes.add(new Day(new DateTime(startDateTime).minusDays(i), true));
}
for (int i = 0; i < daysOfMonth; i++) {
dateTimes.add(new Day(new DateTime(startDateTime).plusDays(i), false));
}
DateTime lastDay = dateTimes.get(dateTimes.size() - 1).getDateTime();
int yy = DAYS_OF_WEEK - lastDay.getDayOfWeek() % DAYS_OF_WEEK;
for (int i = 1; i < yy; i++) {
dateTimes.add(new Day(new DateTime(lastDay).plusDays(i), true));
}
}
示例2: getDateOfCurrentMonday
import org.joda.time.DateTime; //导入方法依赖的package包/类
private String getDateOfCurrentMonday() {
DateTime currentDate = new DateTime();
if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
currentDate = currentDate.plusDays(2);
} else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
currentDate = currentDate.plusDays(1);
} else {
currentDate = currentDate.withDayOfWeek(DateTimeConstants.MONDAY);
}
return currentDate.toString(DATE_PATTERN);
}
示例3: getFirstDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在周的周一
*
* @param date
* @return
*/
public static Date getFirstDayOfWeek(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfWeek = dateTime.getDayOfWeek();
DateTime firstDate = dateTime.minusDays(dayOfWeek - 1);
firstDate = firstDate.withTime(0, 0, 0, 0);
return firstDate.toDate();
}
示例4: getFirstDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在周的周一
*
* @param date
* @return
*/
public static Date getFirstDayOfWeek(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfWeek = dateTime.getDayOfWeek();
DateTime firstDate = dateTime.minusDays(dayOfWeek - 1);
return firstDate.toDate();
}
示例5: getLastDayOfWeek
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 获取某一天所在周的周日
*
* @param date
* @return
*/
public static Date getLastDayOfWeek(Date date) {
DateTime dateTime = new DateTime(date.getTime());
int dayOfWeek = dateTime.getDayOfWeek();
DateTime theDateTime = new DateTime(date.getTime());
theDateTime = theDateTime.plusDays(7 - dayOfWeek);
return theDateTime.toDate();
}
示例6: getExpanded
import org.joda.time.DateTime; //导入方法依赖的package包/类
private boolean getExpanded(String dayDate) {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(DATE_PATTERN);
DateTime dayTime = dateTimeFormatter.parseDateTime(dayDate);
DateTime currentDate = new DateTime();
if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY) {
currentDate = currentDate.plusDays(2);
} else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY) {
currentDate = currentDate.plusDays(1);
}
return DateTimeComparator.getDateOnlyInstance().compare(currentDate, dayTime) == 0;
}
示例7: execute
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
current = current.minusDays(1);
}
int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];
event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
示例8: execute
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public void execute(MessageReceivedEvent event, String[] args) {
DateTime current = new DateTime(DateTimeZone.forID("America/Montreal"));
if (current.getDayOfWeek() == DateTimeConstants.TUESDAY) {
current = current.plusDays(1);
}
while (current.getDayOfWeek() != DateTimeConstants.TUESDAY) {
current = current.plusDays(1);
}
int weeks = Weeks.weeksBetween(Utils.startDateMythicPlus, current).getWeeks();
String[] weekAffixes = Utils.mythicPlusAffixes[weeks % 12];
event.getChannel().sendMessage(Utils.createMythicEmbed(bot, event.getGuild(), weekAffixes).build()).queue();
}
示例9: getWeekday
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 计算当前是星期几
* 返回 星期x
*/
public static String getWeekday(Date date)
{
DateTime dt = new DateTime(date);
String weekday = "";
//星期
switch(dt.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
weekday = "星期日";
break;
case DateTimeConstants.MONDAY:
weekday = "星期一";
break;
case DateTimeConstants.TUESDAY:
weekday = "星期二";
break;
case DateTimeConstants.WEDNESDAY:
weekday = "星期三";
break;
case DateTimeConstants.THURSDAY:
weekday = "星期四";
break;
case DateTimeConstants.FRIDAY:
weekday = "星期五";
break;
case DateTimeConstants.SATURDAY:
weekday = "星期六";
break;
}
return weekday;
}
示例10: getWeekday2
import org.joda.time.DateTime; //导入方法依赖的package包/类
/** 返回 周x */
public static String getWeekday2(Date date)
{
DateTime dt = new DateTime(date);
String weekday = "";
//星期
switch(dt.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
weekday = "周日";
break;
case DateTimeConstants.MONDAY:
weekday = "周一";
break;
case DateTimeConstants.TUESDAY:
weekday = "周二";
break;
case DateTimeConstants.WEDNESDAY:
weekday = "周三";
break;
case DateTimeConstants.THURSDAY:
weekday = "周四";
break;
case DateTimeConstants.FRIDAY:
weekday = "周五";
break;
case DateTimeConstants.SATURDAY:
weekday = "周六";
break;
}
return weekday;
}
示例11: getEnWeekday
import org.joda.time.DateTime; //导入方法依赖的package包/类
/** 返回 SUN,MON,TUE*/
public static String getEnWeekday(Date date)
{
DateTime dt = new DateTime(date);
String weekday = "";
//星期
switch(dt.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
weekday = "SUN";
break;
case DateTimeConstants.MONDAY:
weekday = "MON";
break;
case DateTimeConstants.TUESDAY:
weekday = "TUE";
break;
case DateTimeConstants.WEDNESDAY:
weekday = "WED";
break;
case DateTimeConstants.THURSDAY:
weekday = "THU";
break;
case DateTimeConstants.FRIDAY:
weekday = "FRI";
break;
case DateTimeConstants.SATURDAY:
weekday = "SAT";
break;
}
return weekday;
}
示例12: parseTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 输入时间 XXXX-XX-XX 的字符串, 放回中文指代的时间, 比如 "今天 02/09"
*/
public static String parseTime(String timeText){
DateTime dateTime = new DateTime();
String[] time = timeText.split("-");
int currentMonth = dateTime.getMonthOfYear();
int currentDay = dateTime.getDayOfMonth();
int currentWeak = dateTime.getDayOfWeek();
int currentYear = dateTime.getYear();
int month = Integer.parseInt(time[1]);
int day = Integer.parseInt(time[2]);
int year = Integer.parseInt(time[0]);
int offset = 0; // 相差量
if (year == currentYear){
//如果是同一年:
if (month == currentMonth){
// 如果是同一个月
offset = day - currentDay;
}else{
offset = day + parseMonth(currentMonth, currentYear) - currentDay;
}
}else{
offset = 31 - currentDay + day;
}
String monthAndDay = time[1] + "/" + time[2];
if (offset == 0) return "今天 " + monthAndDay;
if (offset == 1) return "明天 " + monthAndDay;
return parseWeak(currentWeak + offset) + " " + monthAndDay;
}
示例13: getMsgFormatTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 得到仿微信日期格式输出
*
* @param msgTimeMillis
* @return
*/
public static String getMsgFormatTime(long msgTimeMillis) {
DateTime nowTime = new DateTime();
// LogUtils.sf("nowTime = " + nowTime);
DateTime msgTime = new DateTime(msgTimeMillis);
// LogUtils.sf("msgTime = " + msgTime);
int days = Math.abs(Days.daysBetween(msgTime, nowTime).getDays());
// LogUtils.sf("days = " + days);
if (days < 1) {
//早上、下午、晚上 1:40
return getTime(msgTime);
} else if (days == 1) {
//昨天
return "昨天 " + getTime(msgTime);
} else if (days <= 7) {
//星期
switch (msgTime.getDayOfWeek()) {
case DateTimeConstants.SUNDAY:
return "周日 " + getTime(msgTime);
case DateTimeConstants.MONDAY:
return "周一 " + getTime(msgTime);
case DateTimeConstants.TUESDAY:
return "周二 " + getTime(msgTime);
case DateTimeConstants.WEDNESDAY:
return "周三 " + getTime(msgTime);
case DateTimeConstants.THURSDAY:
return "周四 " + getTime(msgTime);
case DateTimeConstants.FRIDAY:
return "周五 " + getTime(msgTime);
case DateTimeConstants.SATURDAY:
return "周六 " + getTime(msgTime);
}
return "";
} else {
//12月22日
return msgTime.toString("MM月dd日 " + getTime(msgTime));
}
}
示例14: parseTime
import org.joda.time.DateTime; //导入方法依赖的package包/类
/**
* 解析API传回的时间 XXXX-XX-XX 的字符串, 转换为中文指代的时间, 比如 "今天 02/09"
*/
public static String parseTime(String timeText){
DateTime dateTime = new DateTime();
String[] time = timeText.split("-");
int currentMonth = dateTime.getMonthOfYear();
int currentDay = dateTime.getDayOfMonth();
int currentWeak = dateTime.getDayOfWeek();
int currentYear = dateTime.getYear();
int month = Integer.parseInt(time[1]);
int day = Integer.parseInt(time[2]);
int year = Integer.parseInt(time[0]);
int offset = 0; // 相差量
if (year == currentYear){
//如果是同一年:
if (month == currentMonth){
// 如果是同一个月
offset = day - currentDay;
}else{
offset = day + parseMonth(currentMonth, currentYear) - currentDay;
}
}else{
offset = 31 - currentDay + day;
}
String monthAndDay = time[1] + "/" + time[2];
if (offset == 0) return "今天 " + monthAndDay;
if (offset == 1) return "明天 " + monthAndDay;
return parseWeak(currentWeak + offset) + " " + monthAndDay;
}
示例15: isWeekend
import org.joda.time.DateTime; //导入方法依赖的package包/类
@Override
public boolean isWeekend(DateTime day) {
return day.getDayOfWeek() == DateTimeConstants.SATURDAY || day.getDayOfWeek() == DateTimeConstants.SUNDAY;
}