Java Code Examples for org.joda.time.DateTimeConstants#SATURDAY

The following examples show how to use org.joda.time.DateTimeConstants#SATURDAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Alarm.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private static int jodaWDToJavaWD(int wd) {
    switch (wd) {
        case DateTimeConstants.MONDAY:
            return Calendar.MONDAY;
        case DateTimeConstants.TUESDAY:
            return Calendar.TUESDAY;
        case DateTimeConstants.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case DateTimeConstants.THURSDAY:
            return Calendar.THURSDAY;
        case DateTimeConstants.FRIDAY:
            return Calendar.FRIDAY;
        case DateTimeConstants.SATURDAY:
            return Calendar.SATURDAY;
        case DateTimeConstants.SUNDAY:
            return Calendar.SUNDAY;
    }
    return 0;
}
 
Example 2
Source File: Alarm.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
private static int jodaWDToJavaWD(int wd) {
    switch (wd) {
        case DateTimeConstants.MONDAY:
            return Calendar.MONDAY;
        case DateTimeConstants.TUESDAY:
            return Calendar.TUESDAY;
        case DateTimeConstants.WEDNESDAY:
            return Calendar.WEDNESDAY;
        case DateTimeConstants.THURSDAY:
            return Calendar.THURSDAY;
        case DateTimeConstants.FRIDAY:
            return Calendar.FRIDAY;
        case DateTimeConstants.SATURDAY:
            return Calendar.SATURDAY;
        case DateTimeConstants.SUNDAY:
            return Calendar.SUNDAY;
    }
    return 0;
}
 
Example 3
Source File: TimeUtils.java    From LQRWeChat with MIT License 5 votes vote down vote up
/**
     * 得到仿微信日期格式输出
     *
     * @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));
        }
    }
 
Example 4
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns a date a number of workdays away. Saturday and Sundays are not considered working days.
 */
@Function("WORKDAY")
@FunctionParameters({
	@FunctionParameter("dateObject"),
	@FunctionParameter("workdays")})
public Date WORKDAY(Object dateObject, Integer workdays){
	Date convertedDate = convertDateObject(dateObject);
	if(convertedDate==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		boolean lookBack = workdays<0;
		DateTime cursorDT=new DateTime(convertedDate);
		int remainingDays=Math.abs(workdays);
		while(remainingDays>0){
			int dayOfWeek = cursorDT.getDayOfWeek();
			if(!(dayOfWeek==DateTimeConstants.SATURDAY || 
					dayOfWeek==DateTimeConstants.SUNDAY)){
				// Decrement remaining days only when it is not Saturday or Sunday
				remainingDays--;
			}
			if(!lookBack) {
				cursorDT= dayOfWeek==DateTimeConstants.FRIDAY?cursorDT.plusDays(3):cursorDT.plusDays(1);
			}
			else {
				cursorDT= dayOfWeek==DateTimeConstants.MONDAY?cursorDT.minusDays(3):cursorDT.minusDays(1);
			}
		}
		return cursorDT.toDate();
	}
}
 
Example 5
Source File: DateTimeFunctions.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Returns the number of working days between two dates (inclusive). Saturday and Sunday are not considered working days.
 */
@Function("NETWORKDAYS")
@FunctionParameters({
	@FunctionParameter("startDate"),
	@FunctionParameter("endDate")})
public Integer NETWORKDAYS(Object startDate, Object endDate){
	Date startDateObj = convertDateObject(startDate);
	if(startDateObj==null) {
		logCannotConvertToDate();
		return null;
	}
	Date endDateObj = convertDateObject(endDate);
	if(endDateObj==null){
		logCannotConvertToDate();
		return null;
	}
	else{
		LocalDate cursorLocalDate=new LocalDate(startDateObj);
		LocalDate endLocalDate=new LocalDate(endDateObj);
		int workingDays=0;
		if(cursorLocalDate.isAfter(endLocalDate)){
			// Swap data information
			LocalDate tmp=cursorLocalDate;
			cursorLocalDate=endLocalDate;
			endLocalDate=tmp;
		}
		while (Days.daysBetween(cursorLocalDate, endLocalDate).getDays()>0){
			int dayOfWeek = cursorLocalDate.getDayOfWeek();
			if(!(dayOfWeek==DateTimeConstants.SATURDAY || 
					dayOfWeek==DateTimeConstants.SUNDAY)){
				workingDays++;
			}
			cursorLocalDate=cursorLocalDate.plusDays(1);
		}
		return workingDays;
	}
}
 
Example 6
Source File: WeeklySaturdayExpiryDayValidator.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected int weekStarts() {
    return DateTimeConstants.SATURDAY;
}
 
Example 7
Source File: Jodatime.java    From maven-framework-project with MIT License 4 votes vote down vote up
private static void getTimeInfo(){
	
	System.out.println("-------------获取当前时间-----------------");
	
	String weekStr="";
	
	DateTime dt = new DateTime();
	//年
	int year = dt.getYear();
	//月
	int month = dt.getMonthOfYear();
	//日
	int day = dt.getDayOfMonth();
	//星期
	int week = dt.getDayOfWeek();
	//点
	int hour = dt.getHourOfDay();
	//分
	int min = dt.getMinuteOfHour();
	//秒
	int sec = dt.getSecondOfMinute();
	//毫秒
	int msec = dt.getMillisOfSecond();
	
	//星期
	switch(week) {
	case DateTimeConstants.SUNDAY:
		weekStr = "星期日";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.MONDAY:
		weekStr = "星期一";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.TUESDAY:
		weekStr = "星期二";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.WEDNESDAY:
		weekStr = "星期三";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.THURSDAY:
		weekStr = "星期四";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.FRIDAY:
		weekStr = "星期五";
		System.out.println(weekStr);
		break;
	case DateTimeConstants.SATURDAY:
		weekStr = "星期六";
		System.out.println(weekStr);
		break;
	}
	
	System.out.println(year + "/" + month + "/" + day + " " + hour + ":" + min + ":" + sec + ":" + msec + " " + weekStr);
	
}