Java Code Examples for java.util.Date.getMonth()

The following are Jave code examples for showing how to use getMonth() of the java.util.Date class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mumu-core   File: DateUtils.java   View Source Code Vote up 6 votes
/**
 * 取季度
 * 
 * @param date
 * @return
 */
@SuppressWarnings("deprecation")
public static int getQuarter(Date date) {
	if (date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2) {
		return 1;
	} else if (date.getMonth() == 3 || date.getMonth() == 4 || date.getMonth() == 5) {
		return 2;
	} else if (date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8) {
		return 3;
	} else if (date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11) {
		return 4;
	} else {
		return 0;

	}
}
 
Example 2
Project: mumu   File: DateUtils.java   View Source Code Vote up 6 votes
/**
 * 取季度
 * 
 * @param date
 * @return
 */
@SuppressWarnings("deprecation")
public static int getQuarter(Date date) {
	if (date.getMonth() == 0 || date.getMonth() == 1 || date.getMonth() == 2) {
		return 1;
	} else if (date.getMonth() == 3 || date.getMonth() == 4 || date.getMonth() == 5) {
		return 2;
	} else if (date.getMonth() == 6 || date.getMonth() == 7 || date.getMonth() == 8) {
		return 3;
	} else if (date.getMonth() == 9 || date.getMonth() == 10 || date.getMonth() == 11) {
		return 4;
	} else {
		return 0;

	}
}
 
Example 3
Project: LJFramework   File: TimeUtils.java   View Source Code Vote up 6 votes
/**
 * 获取当天的下一个月
 */
public static String getNextMonth() {
    Date t = new Date();
    String nmonth = new String();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    try {
        //t=sdf.parse(now);
        Date nextmonth = new Date((t.getYear() + (t.getMonth() + 1) / 12),
                (t.getMonth() + 1) % 12, t.getDate());
        nmonth = sdf.format(nextmonth.getTime());
    } catch (Exception e) {

        e.printStackTrace();
    }
    return nmonth;
}
 
Example 4
Project: stynico   File: HelpsMainAdapter.java   View Source Code Vote up 5 votes
private String getCreateTimes(String dates)
   {
       Date old = toDate(dates);
       Date nowtime = new Date(System.currentTimeMillis());
       long values = nowtime.getTime() - old.getTime();
       values = values / 1000;
// Log.e(TAG, "====values  time===" + values);
       if (values < 60 && values > 0)
{
           return  values + "秒前";
       }
       if (values > 60 && values < 60 * 60)
{
           return values / 60 + "分钟前";
       }
       if (values < 60 * 60 * 24 && values > 60 * 60)
{
           return values / 3600 + "小时前";
       }
       if (values < 60 * 60 * 24 * 2 && values > 60 * 60 * 24)
{
           return "昨天";
       }
       if (values < 60 * 60 * 3 * 24 && values > 60 * 60 * 24 * 2)
{
           return  "前天";
       }
       if (values < 60 * 60 * 24 * 30 && values > 60 * 60 * 24 * 3)
{
           return  values / (60 * 60 * 24) + "天前";
       }
       if (values < 60 * 60 * 24 * 365 && values > 60 * 60 * 24 * 30)
{
    return nowtime.getMonth() - old.getMonth() + "个月前";
       }
       return  values / (60 * 60 * 24 * 30 * 365) + "年前";
   }
 
Example 5
Project: ConnectU   File: HorarioRequest.java   View Source Code Vote up 5 votes
private boolean happensHere(Date start, Date current, Date end) {
    if (start.getYear() <= current.getYear() && start.getMonth() <= current.getMonth() && start.getDate() <= current.getDate()) {
        if (current.getYear() <= end.getYear() && current.getMonth() <= end.getMonth() && current.getDate() <= end.getDate()) {
            return true;
        }
    }
    return false;
}
 
Example 6
Project: My-Blog   File: DateKit.java   View Source Code Vote up 5 votes
public static boolean isToday(Date date) {
    Date now = new Date();
    boolean result = true;
    result &= date.getYear() == now.getYear();
    result &= date.getMonth() == now.getMonth();
    result &= date.getDate() == now.getDate();
    return result;
}
 
Example 7
Project: DaUtil   File: TextUtils.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
public static String getShortTimeText(Long oldTime) {
	Date time = parseDate(oldTime, TimeFormat);
	Date now = new Date();
	String format = "yyyy-MM-dd HH:mm";
	if (time.getYear() == now.getYear()) {
		format = format.substring("yyyy-".length());
		if (time.getMonth() == now.getMonth() && time.getDay() == now.getDay()) {
			format = format.substring("MM-dd ".length());
		}
	}
	return formatDate(time, format);
}
 
Example 8
Project: DAFramework   File: TextUtils.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
public static String getShortTimeText(Long oldTime) {
	Date time = parseDate(oldTime, TimeFormat);
	Date now = new Date();
	String format = "yyyy-MM-dd HH:mm";
	if (time.getYear() == now.getYear()) {
		format = format.substring("yyyy-".length());
		if (time.getMonth() == now.getMonth() && time.getDay() == now.getDay()) {
			format = format.substring("MM-dd ".length());
		}
	}
	return formatDate(time, format);
}
 
Example 9
Project: OpenJSharp   File: ZipUtils.java   View Source Code Vote up 5 votes
public static long javaToDosTime(long time) {
    Date d = new Date(time);
    int year = d.getYear() + 1900;
    if (year < 1980) {
        return (1 << 21) | (1 << 16);
    }
    return (year - 1980) << 25 | (d.getMonth() + 1) << 21 |
           d.getDate() << 16 | d.getHours() << 11 | d.getMinutes() << 5 |
           d.getSeconds() >> 1;
}
 
Example 10
Project: healthgo   File: WeatherChartView.java   View Source Code Vote up 5 votes
public static String[] get6days(boolean returnString)
{
    Date d=getToday();

    String [] days=new String[6];
    for (int i=0;i<6;i++)
    {
        Date t=add(d,i-2);
        days[i]=t.getMonth()+1+"."+t.getDate();
    }
    return days;
}
 
Example 11
Project: uavstack   File: DateTimeHelper.java   View Source Code Vote up 5 votes
/**
 * 测试是否是当天
 * 
 * @param date
 *            某一日期
 * @return true 今天, false-不是
 */
@SuppressWarnings("deprecation")
public static boolean isToday(Date date) {

    Date now = new Date();
    boolean result = true;
    result &= date.getYear() == now.getYear();
    result &= date.getMonth() == now.getMonth();
    result &= date.getDate() == now.getDate();
    return result;
}
 
Example 12
Project: openjdk-jdk10   File: CompilationStatistics.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
public static void clear(String dumpName) {
    try {
        ConcurrentLinkedDeque<CompilationStatistics> snapshot = list;
        long snapshotZeroTime = zeroTime;

        list = new ConcurrentLinkedDeque<>();
        zeroTime = System.nanoTime();

        Date now = new Date();
        String dateString = (now.getYear() + 1900) + "-" + (now.getMonth() + 1) + "-" + now.getDate() + "-" + now.getHours() + "" + now.getMinutes();

        dumpCompilations(snapshot, dumpName, dateString);

        try (FileOutputStream fos = new FileOutputStream("timeline_" + dateString + "_" + dumpName + ".csv", true); PrintStream out = new PrintStream(fos)) {

            long[] timeSpent = new long[10000];
            int maxTick = 0;
            for (CompilationStatistics stats : snapshot) {
                long start = stats.startTime - snapshotZeroTime;
                long duration = stats.duration;
                if (start < 0) {
                    duration -= -start;
                    start = 0;
                }

                int tick = (int) (start / RESOLUTION);
                long timeLeft = RESOLUTION - (start % RESOLUTION);

                while (tick < timeSpent.length && duration > 0) {
                    if (tick > maxTick) {
                        maxTick = tick;
                    }
                    timeSpent[tick] += Math.min(timeLeft, duration);
                    duration -= timeLeft;
                    tick++;
                    timeLeft = RESOLUTION;
                }
            }
            String timelineName = System.getProperty("stats.timeline.name");
            if (timelineName != null && !timelineName.isEmpty()) {
                out.printf("%s%c", CSVUtil.Escape.escape(timelineName), CSVUtil.SEPARATOR);
            }
            for (int i = 0; i < maxTick; i++) {
                out.printf("%d%c", normalize(timeSpent[i]), CSVUtil.SEPARATOR);
            }
            // print last column
            out.printf("%d", normalize(timeSpent[maxTick]));
            out.println();
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Project: calendar-component   File: DateConstants.java   View Source Code Vote up 4 votes
public static CalDate toRPCDate(Date date) {
    return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
 
Example 14
Project: HL4A   File: 时间工具.java   View Source Code Vote up 4 votes
public static Integer 月份(Date $时间) {
		return $时间.getMonth();
}
 
Example 15
Project: LucaHome-AndroidApplication   File: CalendarEntryDto.java   View Source Code Vote up 4 votes
public boolean IsToday() {
    Calendar calendar = Calendar.getInstance();
    Date now = calendar.getTime();
    return _begin.getDay() == now.getDay() && _begin.getMonth() == now.getMonth() && _begin.getYear() == now.getYear();
}
 
Example 16
Project: Cybernet-VPN   File: X509Utils.java   View Source Code Vote up 4 votes
public static int getMonthsDifference(Date date1, Date date2) {
    int m1 = date1.getYear() * 12 + date1.getMonth();
    int m2 = date2.getYear() * 12 + date2.getMonth();
    return m2 - m1 + 1;
}
 
Example 17
Project: healthgo   File: DateTimeHelper.java   View Source Code Vote up 4 votes
public static Date getToday()
{
    Date d=new Date();
    return new Date(d.getYear(),d.getMonth(),d.getDate());
}
 
Example 18
Project: jdk8u-jdk   File: Bug6772689.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}
 
Example 19
Project: alfresco-remote-api   File: BlogPostsPerMonthGet.java   View Source Code Vote up 4 votes
/**
 * Fetches data for each month for which posts exist, plus the count of each.
 * Note: If no posts could be found, this method will return the current month
 *       but with a count of posts equals zero.
 * Ported from blog-posts-per-month.get.js
 */
@SuppressWarnings("deprecation")
private List<Map<String, Object>> getBlogPostMonths(PagingResults<BlogPostInfo> nodes)
{
    // will hold the months information
    List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();
   
    // do we have posts?
    if (!nodes.getPage().isEmpty())
    {
        int currYear = -1;
        int currMonth = -1;
        Map<String, Object> currData = null;
        for (int x = 0; x < nodes.getPage().size(); x++)
        {
            NodeRef node = nodes.getPage().get(x).getNodeRef();
            Date date = (Date) nodeService.getProperty(node, ContentModel.PROP_PUBLISHED);
            
            // is this a new month?
            if (currYear != date.getYear() + 1900 || currMonth != date.getMonth())
            {
                currYear = date.getYear() + 1900;
                currMonth = date.getMonth();
                currData = getMonthDataObject(date);
                data.add(currData);
            }
            // otherwise just increment the counter
            else
            {
                Object countObj = currData.get("count");
                Integer countInt = countObj == null ? 0 : (Integer)countObj;
                
                currData.put("count", countInt + 1);
            }
        }
    }
    // if not, add the current month with count = 0
    else
    {
        Map<String, Object> emptyData = getMonthDataObject(new Date());
        emptyData.put("count", 0);
        data.add(emptyData);
    }
    
    return data;
}
 
Example 20
Project: openjdk-jdk10   File: Bug6772689.java   View Source Code Vote up 4 votes
public static void main(String[] args) {
    TimeZone defaultTimeZone = TimeZone.getDefault();
    int errors = 0;

    Calendar cal = new GregorianCalendar(BEGIN_YEAR, MARCH, 1);
    String[] tzids = TimeZone.getAvailableIDs();
    try {
        for (String id : tzids) {
            TimeZone tz = TimeZone.getTimeZone(id);
            if (!tz.useDaylightTime()) {
                continue;
            }
            TimeZone.setDefault(tz);

          dateloop:
            // Use future dates because sun.util.calendar.ZoneInfo
            // delegates offset transition calculations to a SimpleTimeZone
            // (after 2038 as of JDK7).
            for (int year = BEGIN_YEAR; year < END_YEAR; year++) {
                for (int month = MARCH; month <= NOVEMBER; month++) {
                    cal.set(year, month, 1, 15, 0, 0);
                    int maxDom = cal.getActualMaximum(DAY_OF_MONTH);
                    for (int dom = 1; dom <= maxDom; dom++) {
                        Date date = new Date(year - 1900, month, dom);
                        if (date.getYear()+1900 != year
                            || date.getMonth() != month
                            || date.getDate() != dom) {
                            System.err.printf("%s: got %04d-%02d-%02d, expected %04d-%02d-%02d%n",
                                              id,
                                              date.getYear() + 1900,
                                              date.getMonth() + 1,
                                              date.getDate(),
                                              year,
                                              month + 1,
                                              dom);
                            errors++;
                            break dateloop;
                        }
                    }
                }
            }
        }
    } finally {
        // Restore the default TimeZone.
        TimeZone.setDefault(defaultTimeZone);
    }
    if (errors > 0) {
        throw new RuntimeException("Transition test failed");
    }
}