本文整理汇总了Java中java.util.Date.getMonth方法的典型用法代码示例。如果您正苦于以下问题:Java Date.getMonth方法的具体用法?Java Date.getMonth怎么用?Java Date.getMonth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Date
的用法示例。
在下文中一共展示了Date.getMonth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getQuarter
import java.util.Date; //导入方法依赖的package包/类
/**
* 取季度
*
* @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;
}
}
示例2: getNextMonth
import java.util.Date; //导入方法依赖的package包/类
/**
* 获取当天的下一个月
*/
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;
}
示例3: getCreateTimes
import java.util.Date; //导入方法依赖的package包/类
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) + "年前";
}
示例4: happensHere
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例5: isToday
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例6: getShortTimeText
import java.util.Date; //导入方法依赖的package包/类
@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);
}
示例7: javaToDosTime
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例8: get6days
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例9: isToday
import java.util.Date; //导入方法依赖的package包/类
/**
* 测试是否是当天
*
* @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;
}
示例10: clear
import java.util.Date; //导入方法依赖的package包/类
@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);
}
}
示例11: toRPCDate
import java.util.Date; //导入方法依赖的package包/类
public static CalDate toRPCDate(Date date) {
return new CalDate(date.getYear() + 1900, date.getMonth() + 1, date.getDate());
}
示例12:
import java.util.Date; //导入方法依赖的package包/类
public static Integer 月份(Date $时间) {
return $时间.getMonth();
}
示例13: IsToday
import java.util.Date; //导入方法依赖的package包/类
public boolean IsToday() {
Calendar calendar = Calendar.getInstance();
Date now = calendar.getTime();
return _begin.getDay() == now.getDay() && _begin.getMonth() == now.getMonth() && _begin.getYear() == now.getYear();
}
示例14: getMonthsDifference
import java.util.Date; //导入方法依赖的package包/类
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;
}
示例15: getToday
import java.util.Date; //导入方法依赖的package包/类
public static Date getToday()
{
Date d=new Date();
return new Date(d.getYear(),d.getMonth(),d.getDate());
}