本文整理汇总了Java中java.util.Calendar.getInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Calendar.getInstance方法的具体用法?Java Calendar.getInstance怎么用?Java Calendar.getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Calendar
的用法示例。
在下文中一共展示了Calendar.getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addAlarm
import java.util.Calendar; //导入方法依赖的package包/类
public void addAlarm(Date date, int id, String data, int interval, boolean repeating, boolean wakeUpScreen) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy 'at' h:mm a");
// intent
Intent intent = new Intent(c, AlarmReceiver.class);
intent.putExtra(ALARM_INTENT, data);
intent.putExtra(Project.SETTINGS_SCREEN_WAKEUP, wakeUpScreen);
intent.putExtra(Project.NAME, mProject.getName());
intent.putExtra(Project.FOLDER, mProject.getFolder());
PendingIntent sender = PendingIntent.getBroadcast(c, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Set Alarm
if (repeating) mAlarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), interval, sender);
else mAlarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), sender);
// add to a global alarm thingie
addTask(new Task(id, mProject, Task.TYPE_ALARM ,cal, interval, repeating, wakeUpScreen));
}
示例2: formatDateChat
import java.util.Calendar; //导入方法依赖的package包/类
public static String formatDateChat(long date) {
try {
Calendar rightNow = Calendar.getInstance();
int year = rightNow.get(Calendar.YEAR);
rightNow.setTimeInMillis(date * 1000);
int dateYear = rightNow.get(Calendar.YEAR);
if (year == dateYear) {
return getInstance().chatDate.format(date * 1000);
}
return getInstance().chatFullDate.format(date * 1000);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
return "LOC_ERR: formatDateChat";
}
示例3: isNowBetween
import java.util.Calendar; //导入方法依赖的package包/类
/**
* 判断当前时间是否在两个时间段之内
*
* @param beginTime 开始时间
* @param endTime 结束时间
* @return
*/
public static boolean isNowBetween(String beginTime, String endTime) {
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date now = null;
Date begin = null;
Date end = null;
try {
now = df.parse(df.format(new Date()));
begin = df.parse(beginTime);
end = df.parse(endTime);
} catch (Exception e) {
e.printStackTrace();
}
Calendar nowCal = Calendar.getInstance();
nowCal.setTime(now);
Calendar beginCal = Calendar.getInstance();
beginCal.setTime(begin);
Calendar endCal = Calendar.getInstance();
endCal.setTime(end);
if (nowCal.after(beginCal) && nowCal.before(endCal)) {
return true;
} else {
return false;
}
}
示例4: getBeginOfMonthDate
import java.util.Calendar; //导入方法依赖的package包/类
/**
* Ported from blog-posts-per-month.get.js
*/
@SuppressWarnings("deprecation")
private Date getBeginOfMonthDate(Date date)
{
//TODO These date processing methods are copied almost verbatim from JavaScript to preserve behaviour.
// However they should be updated to use java.util.Calendar as the current implementation assumes a Gregorian calendar.
Calendar calendar = Calendar.getInstance();
calendar.set(date.getYear(), date.getMonth(), 1);
return calendar.getTime();
}
示例5: getMonthFromDate
import java.util.Calendar; //导入方法依赖的package包/类
public static int getMonthFromDate(Date date) {
int month = 1;
if (date != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
month = calendar.get(Calendar.MONTH);
calendar.setTime(date);
month = calendar.get(Calendar.MONTH);
}
return month;
}
示例6: ThingDescription
import java.util.Calendar; //导入方法依赖的package包/类
public ThingDescription(String id, String time) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
this.id = id;
this.lifetime = Calendar.getInstance();
try {
this.lifetime.setTime(dateFormat.parse(time));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例7: lengthOfYear
import java.util.Calendar; //导入方法依赖的package包/类
@Override
public int lengthOfYear() {
Calendar jcal = Calendar.getInstance(JapaneseChronology.LOCALE);
jcal.set(Calendar.ERA, era.getValue() + JapaneseEra.ERA_OFFSET);
jcal.set(yearOfEra, isoDate.getMonthValue() - 1, isoDate.getDayOfMonth());
return jcal.getActualMaximum(Calendar.DAY_OF_YEAR);
}
示例8: handleClick
import java.util.Calendar; //导入方法依赖的package包/类
@Override public void handleClick(MonthCellDescriptor cell) {
Date clickedDate = cell.getDate();
if(highlightedCells.contains(cell)){
return;
}
Calendar calendar = Calendar.getInstance();
calendar.setTime(clickedDate);
int day = calendar.get(DAY_OF_WEEK);
if(deactivatedDates.contains(day)){
return;
}
if (cellClickInterceptor != null && cellClickInterceptor.onCellClicked(clickedDate)) {
return;
}
if (!betweenDates(clickedDate, minCal, maxCal) || !isDateSelectable(clickedDate)) {
if (invalidDateListener != null) {
invalidDateListener.onInvalidDateSelected(clickedDate);
}
} else {
boolean wasSelected = doSelectDate(clickedDate, cell);
if (dateListener != null) {
if (wasSelected) {
dateListener.onDateSelected(clickedDate);
} else {
dateListener.onDateUnselected(clickedDate);
}
}
}
}
示例9: getLastmondayInt
import java.util.Calendar; //导入方法依赖的package包/类
public static String getLastmondayInt() {
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, getMondayPlus() - 7);
return format(cal.getTime(), "yyyyMMdd");
}
示例10: computNextHourTimeMillis
import java.util.Calendar; //导入方法依赖的package包/类
public static long computNextHourTimeMillis() {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.add(Calendar.DAY_OF_MONTH, 0);
cal.add(Calendar.HOUR_OF_DAY, 1);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
return cal.getTimeInMillis();
}
示例11: getGmtCalendar
import java.util.Calendar; //导入方法依赖的package包/类
protected Calendar getGmtCalendar() {
// Worst case we allocate this twice and the other gets GC'd,
// however prevents deadlock
if (this.gmtCalendar == null) {
this.gmtCalendar = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
}
return this.gmtCalendar;
}
示例12: bindView
import java.util.Calendar; //导入方法依赖的package包/类
@Override
protected void bindView(BlotterViewHolder v, Context context, Cursor cursor) {
long toAccountId = cursor.getLong(BlotterColumns.to_account_id.ordinal());
String payee = cursor.getString(BlotterColumns.payee.ordinal());
String note = cursor.getString(BlotterColumns.note.ordinal());
long locationId = cursor.getLong(BlotterColumns.location_id.ordinal());
String location = "";
if (locationId > 0) {
location = cursor.getString(BlotterColumns.location.ordinal());
}
String toAccount = cursor.getString(BlotterColumns.to_account_title.ordinal());
long fromAmount = cursor.getLong(BlotterColumns.from_amount.ordinal());
if (toAccountId > 0) {
v.topView.setText(R.string.transfer);
if (fromAmount > 0) {
note = toAccount+" \u00BB";
} else {
note = "\u00AB "+toAccount;
}
u.setTransferTextColor(v.centerView);
} else {
String title = cursor.getString(BlotterColumns.from_account_title.ordinal());
v.topView.setText(title);
v.centerView.setTextColor(Color.WHITE);
}
long categoryId = cursor.getLong(BlotterColumns.category_id.ordinal());
String category = "";
if (categoryId != 0) {
category = cursor.getString(BlotterColumns.category_title.ordinal());
}
String text = generateTransactionTitle(sb, payee, note, location, categoryId, category);
v.centerView.setText(text);
sb.setLength(0);
long currencyId = cursor.getLong(BlotterColumns.from_account_currency_id.ordinal());
Currency c = CurrencyCache.getCurrency(em, currencyId);
long originalCurrencyId = cursor.getLong(BlotterColumns.original_currency_id.ordinal());
if (originalCurrencyId > 0) {
Currency originalCurrency = CurrencyCache.getCurrency(em, originalCurrencyId);
long originalAmount = cursor.getLong(BlotterColumns.original_from_amount.ordinal());
u.setAmountText(sb, v.rightCenterView, originalCurrency, originalAmount, c, fromAmount, true);
} else {
u.setAmountText(v.rightCenterView, c, fromAmount, true);
}
if (fromAmount > 0) {
v.iconView.setImageDrawable(icBlotterIncome);
} else if (fromAmount < 0) {
v.iconView.setImageDrawable(icBlotterExpense);
}
long date = cursor.getLong(BlotterColumns.datetime.ordinal());
v.bottomView.setText(DateUtils.formatDateTime(context, date,
DateUtils.FORMAT_SHOW_DATE|DateUtils.FORMAT_SHOW_WEEKDAY|DateUtils.FORMAT_ABBREV_WEEKDAY|DateUtils.FORMAT_SHOW_TIME|DateUtils.FORMAT_ABBREV_MONTH));
if (date > System.currentTimeMillis()) {
u.setFutureTextColor(v.bottomView);
} else {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(date);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
if (dayOfWeek == Calendar.SUNDAY || dayOfWeek == Calendar.SATURDAY) {
v.bottomView.setTextColor(Color.rgb(224, 112, 112));
} else {
v.bottomView.setTextColor(v.topView.getTextColors().getDefaultColor());
}
}
long balance = cursor.getLong(BlotterColumns.from_account_balance.ordinal());
v.rightView.setText(Utils.amountToString(c, balance, false));
removeRightViewIfNeeded(v);
setIndicatorColor(v, cursor);
}
示例13: getDay
import java.util.Calendar; //导入方法依赖的package包/类
public static Date getDay(String dateString, int dayNum) {
Calendar cal = Calendar.getInstance();
cal.setTime(string2date(dateString, "yyyy-MM-dd"));
cal.add(5, dayNum);
return cal.getTime();
}
示例14: JspCalendar
import java.util.Calendar; //导入方法依赖的package包/类
public JspCalendar() {
calendar = Calendar.getInstance();
Date trialTime = new Date();
calendar.setTime(trialTime);
}
示例15: doInBackground
import java.util.Calendar; //导入方法依赖的package包/类
@Override
protected Calendar doInBackground(Void... unused) {
return Calendar.getInstance();
}