本文整理匯總了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());
}