本文整理匯總了Java中java.util.GregorianCalendar.getTime方法的典型用法代碼示例。如果您正苦於以下問題:Java GregorianCalendar.getTime方法的具體用法?Java GregorianCalendar.getTime怎麽用?Java GregorianCalendar.getTime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.GregorianCalendar
的用法示例。
在下文中一共展示了GregorianCalendar.getTime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLocalDateAndTime
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* Converts an SNMP string representation into a {@link Date} object,
* and applies time zone conversion to provide the time on the local machine, ie PSM server.
*
* @param actAlarmDateAndTime MIB-II DateAndTime formatted. May optionally contain
* a timezone offset in 3 extra bytes
* @param sysInfoTimeZone Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
* @param swVersion Must be supplied if actAlarmDateAndTime is just local time (with no timezone)
* @return adjusted {@link Date} or a simple conversion if other fields are null.
*/
public static Date getLocalDateAndTime(String actAlarmDateAndTime, String sysInfoTimeZone,
String swVersion) {
if (StringUtils.isBlank(actAlarmDateAndTime)) {
return null;
}
GregorianCalendar decodedDateAndTimeCal = btiMakeCalendar(OctetString.fromHexString(actAlarmDateAndTime));
if ((sysInfoTimeZone == null) || (swVersion == null)) {
return decodedDateAndTimeCal.getTime();
}
TimeZone javaTimeZone = getTimeZone();
decodedDateAndTimeCal.setTimeZone(javaTimeZone);
GregorianCalendar localTime = new GregorianCalendar();
localTime.setTimeInMillis(decodedDateAndTimeCal.getTimeInMillis());
return localTime.getTime();
}
示例2: recupInfoEtudiant
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* @param ine
* @return un individu Apogee anonyme
*/
public WSIndividu recupInfoEtudiant(String ine) {
WSIndividu ind = null;
GregorianCalendar cal = new GregorianCalendar();
cal.set(1992, 2, 12);
if (ine!=null && ine.equals("0000000000") || ine.equals("1111111111") || ine.equals("2222222222") || ine.equals("3333333333") || ine.equals("4444444444") ||
ine.equals("5555555555") || ine.equals("6666666666") || ine.equals("7777777777") || ine.equals("8888888888") || ine.equals("9999999999")){
String cpt = ine.substring(0, 1);
ind = new WSIndividu(1, "1", "057", new BigDecimal(ine), ine, "A", "D", cal.getTime(), "NomPat-"+cpt, "NomUsu-"+cpt, "Prenom1-"+cpt, "Prenom2-"+cpt, "Metz", "100");
ind.setAdresse(new WSAdresse(1, "57000", "57463", "100", "15 rue de Nancy", "Etage 1", "Porte droite", "0383542120", "0612356421"));
ind.setBac(new WSBac(new Long(ine), "S", "057", "0573227Y", null, "2009", "O"));
List<WSCursusInterne> listCursusInterne = new ArrayList<WSCursusInterne>();
listCursusInterne.add(new WSCursusInterne("VET001-001", "License 1 - Droit", "2010", "AB", "1"));
listCursusInterne.add(new WSCursusInterne("VET001-002", "License 2 - Droit", "2011", "P", "1"));
listCursusInterne.add(new WSCursusInterne("VET001-003", "License 2 - Droit", "2012", "P", "1"));
listCursusInterne.add(new WSCursusInterne("VET001-004", "Master 1 - Droit", "2013", "B", "1"));
listCursusInterne.add(new WSCursusInterne("VET001-005", "Master 2 - Droit", "2014", "P", "1"));
ind.setListCursusInterne(listCursusInterne);
}
return ind;
}
示例3: dowTest
import java.util.GregorianCalendar; //導入方法依賴的package包/類
void dowTest(boolean lenient) {
GregorianCalendar cal = new GregorianCalendar();
cal.set(1997, AUGUST, 12); // Wednesday
cal.getTime(); // Force update
cal.setLenient(lenient);
cal.set(1996, DECEMBER, 1); // Set the date to be December 1, 1996
int dow = cal.get(DAY_OF_WEEK);
int min = cal.getMinimum(DAY_OF_WEEK);
int max = cal.getMaximum(DAY_OF_WEEK);
if (dow < min || dow > max) {
errln("FAIL: Day of week " + dow + " out of range");
}
if (dow != SUNDAY) {
errln("FAIL2: Day of week should be SUNDAY; is " + dow + ": " + cal.getTime());
}
if (min != SUNDAY || max != SATURDAY) {
errln("FAIL: Min/max bad");
}
}
示例4: getThisWeek
import java.util.GregorianCalendar; //導入方法依賴的package包/類
Pair<Date, Date> getThisWeek() {
final GregorianCalendar today = new GregorianCalendar();
today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));
final Date end = today.getTime();
today.add(Calendar.DATE, -(today.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY));
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
return new Pair<>(today.getTime(), end);
}
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:18,代碼來源:AllowanceOverviewPresenter.java
示例5: getToday
import java.util.GregorianCalendar; //導入方法依賴的package包/類
Pair<Date, Date> getToday() {
final GregorianCalendar today = new GregorianCalendar();
today.set(Calendar.HOUR_OF_DAY, today.getActualMaximum(Calendar.HOUR_OF_DAY));
today.set(Calendar.MINUTE, today.getActualMaximum(Calendar.MINUTE));
today.set(Calendar.SECOND, today.getActualMaximum(Calendar.SECOND));
today.set(Calendar.MILLISECOND, today.getActualMaximum(Calendar.MILLISECOND));
final Date end = today.getTime();
today.add(Calendar.DATE, -1);
today.set(Calendar.HOUR_OF_DAY, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.SECOND, 0);
today.set(Calendar.MILLISECOND, 0);
return new Pair<>(today.getTime(), end);
}
開發者ID:PacktPublishing,項目名稱:Hands-On-Android-UI-Development,代碼行數:17,代碼來源:AllowanceOverviewPresenter.java
示例6: handleDateTimeByYear
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* <pre>
* 描述:間隔指定年數的指定月份指定周數指定星期數後日期(例如:每年1月份第一個星期一)
* 作者:ZhangYi
* 時間:2016年5月5日 下午4:29:07
* 參數:(參數列表)
* @param dateTime 指定日期
* @param interval 間隔年(間隔幾年)
* @param month 指定月份(1-12:月份)
* @param num 指定周數(1-4:第幾個星期)
* @param week 指定周幾(1-7:周一至周日,-1:不指定周幾[默認星期一])
* @return
* </pre>
*/
public static Date handleDateTimeByYear(Date dateTime, int interval, int month, int num, int week) {
try {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(dateTime);
calendar.add(Calendar.YEAR, interval);
calendar.set(Calendar.MONTH, month - 1);
if (num < 0) {// 最後一個星期
calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, -1);
} else {
calendar.set(Calendar.DAY_OF_WEEK_IN_MONTH, num);
}
if (week < 0) {// [默認星期一]
calendar.set(Calendar.DAY_OF_WEEK, 1 % 7 + 1);
} else {
calendar.set(Calendar.DAY_OF_WEEK, week % 7 + 1);
}
dateTime = calendar.getTime();
} catch (Exception e) {
logger.error("--間隔指定年數的指定月份指定周數指定星期數後日期異常!", e);
}
return dateTime;
}
示例7: storeHoliday
import java.util.GregorianCalendar; //導入方法依賴的package包/類
private static boolean storeHoliday(int year, GregorianCalendar cal, Holiday holiday, HashMap<Date, HolidayVO> holidayMap) {
boolean inserted;
if (cal.get(GregorianCalendar.YEAR) == year) {
HolidayVO holidayVO;
Date date = cal.getTime();
if (holidayMap.containsKey(date)) {
holidayVO = holidayMap.get(date);
inserted = false;
} else {
holidayVO = new HolidayVO();
holidayMap.put(date, holidayVO);
holidayVO.setDate(date);
holidayVO.setHoliday(false);
inserted = true;
}
holidayVO.getNameL10nKeys().add(holiday.getNameL10nKey());
holidayVO.setHoliday(holidayVO.getHoliday() || holiday.isHoliday());
} else {
inserted = false;
}
return inserted;
}
示例8: getCurrentWeekday
import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static String getCurrentWeekday() {
int mondayPlus = DateUtil.getMondayPlus();
GregorianCalendar currentDate = new GregorianCalendar();
currentDate.add(GregorianCalendar.DATE, mondayPlus + 6);
Date monday = currentDate.getTime();
DateFormat df = DateFormat.getDateInstance();
return df.format(monday);
}
示例9: randomDate
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* Génère une date entre dans l'intervalle d'année spécifier.
* @param startYear L'année de départ de l'intervalle
* @param endYear l'année de fin de l'intervalle
* @return La date généré
*/
protected Date randomDate(Integer startYear, Integer endYear) {
ThreadLocalRandom random = ThreadLocalRandom.current();
int month = random.nextInt(1, 12);
int day = 1;
if (month == GregorianCalendar.FEBRUARY) {
day = random.nextInt(1, 28);
} else if (month == GregorianCalendar.APRIL || month == GregorianCalendar.JUNE || month == GregorianCalendar.SEPTEMBER || month == GregorianCalendar.OCTOBER) {
day = random.nextInt(1, 30);
} else {
day = random.nextInt(1, 31);
}
GregorianCalendar gc = new GregorianCalendar(random.nextInt(startYear, endYear), random.nextInt(1, 12), day);
return gc.getTime();
}
示例10: Test4162587
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* Calendar and Date HOUR broken. If HOUR is out-of-range, Calendar
* and Date classes will misbehave.
*/
public void Test4162587() {
TimeZone savedTz = TimeZone.getDefault();
TimeZone tz = TimeZone.getTimeZone("PST");
TimeZone.setDefault(tz);
GregorianCalendar cal = new GregorianCalendar(tz);
Date d;
try {
for (int i = 0; i < 5; ++i) {
if (i > 0) {
logln("---");
}
cal.clear();
cal.set(1998, APRIL, 5, i, 0);
d = cal.getTime();
String s0 = d.toString();
logln("0 " + i + ": " + s0);
cal.clear();
cal.set(1998, APRIL, 4, i + 24, 0);
d = cal.getTime();
String sPlus = d.toString();
logln("+ " + i + ": " + sPlus);
cal.clear();
cal.set(1998, APRIL, 6, i - 24, 0);
d = cal.getTime();
String sMinus = d.toString();
logln("- " + i + ": " + sMinus);
if (!s0.equals(sPlus) || !s0.equals(sMinus)) {
errln("Fail: All three lines must match");
}
}
} finally {
TimeZone.setDefault(savedTz);
}
}
示例11: handleDateTimeByHour
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* <pre>
* 描述:間隔指定小時後日期(例如:每3小時)
* 作者:ZhangYi
* 時間:2016年5月5日 下午4:29:07
* 參數:(參數列表)
* @param dateTime 指定日期
* @param interval 間隔小時
* @return
* </pre>
*/
public static Date handleDateTimeByHour(Date dateTime, int interval) {
try {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(dateTime);
calendar.add(Calendar.HOUR, interval);
dateTime = calendar.getTime();
} catch (Exception e) {
logger.error("--間隔指定小時後日期異常!", e);
}
return dateTime;
}
示例12: sanitizeTimelineTimestamp
import java.util.GregorianCalendar; //導入方法依賴的package包/類
public static Date sanitizeTimelineTimestamp(boolean sub, Date date) {
if (date != null) {
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(date);
cal.add(GregorianCalendar.MILLISECOND, (sub ? -1 : 1) * TimeZone.getDefault().getOffset(date.getTime()));
return cal.getTime();
}
return null;
}
示例13: handleDateTimeByMonth
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* <pre>
* 描述:間隔指定月數的指定天數後日期(例如:每月1日)
* 作者:ZhangYi
* 時間:2016年5月5日 下午4:29:07
* 參數:(參數列表)
* @param dateTime 指定日期
* @param interval 間隔月數(間隔幾個月)
* @param day 指定天數
* @return
* </pre>
*/
public static Date handleDateTimeByMonth(Date dateTime, int interval, int day) {
try {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(dateTime);
calendar.add(Calendar.MONTH, interval);
calendar.set(Calendar.DAY_OF_MONTH, day);
dateTime = calendar.getTime();
} catch (Exception e) {
logger.error("--間隔指定月數的指定天數後日期異常!", e);
}
return dateTime;
}
示例14: getPascalDate
import java.util.GregorianCalendar; //導入方法依賴的package包/類
/**
* Extract a Pascal date from the buffer.<br>
* Bits 0-3: month (1-12)<br>
* Bits 4-8: day (1-31)<br>
* Bits 9-15: year (0-99)
*/
public static Date getPascalDate(byte[] buffer, int offset) {
int pascalDate = getWordValue(buffer, offset);
int month = pascalDate & 0x000f - 1;
int day = (pascalDate & 0x01f0) >> 4;
int year = (pascalDate & 0xfe00) >> 9;
if (year < 50) year+= 2000;
if (year < 100) year+= 1900;
GregorianCalendar gc = new GregorianCalendar(year, month, day);
return gc.getTime();
}
示例15: addSortableNode
import java.util.GregorianCalendar; //導入方法依賴的package包/類
private NodeRef addSortableNode(int position)
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
MLText ml = new MLText();
ml.addValue(Locale.ENGLISH, "Test " + position);
properties.put(ContentModel.PROP_DESCRIPTION, ml);
properties.put(ContentModel.PROP_TITLE, ml);
properties.put(ContentModel.PROP_NAME, "Test " + position);
properties.put(ContentModel.PROP_CREATED, new Date());
properties.put(singleTextUntokenised, orderable[position]);
properties.put(singleTextTokenised, orderable[position]);
properties.put(singleTextBoth, orderable[position]);
properties.put(multipleTextUntokenised, asArray(orderable[position], orderable[position + 1]));
properties.put(multipleTextTokenised, asArray(orderable[position], orderable[position + 1]));
properties.put(multipleTextBoth, asArray(orderable[position], orderable[position + 1]));
properties.put(singleMLTextUntokenised, makeMLText(position));
properties.put(singleMLTextTokenised, makeMLText(position));
properties.put(singleMLTextBoth, makeMLText(position));
properties.put(multipleMLTextUntokenised, makeMLTextMVP(position));
properties.put(multipleMLTextTokenised, makeMLTextMVP(position));
properties.put(multipleMLTextBoth, makeMLTextMVP(position));
properties.put(singleFloat, 1.1f * position);
properties.put(multipleFloat, asArray(1.1f * position, 2.2f * position));
properties.put(singleDouble, 1.1d * position);
properties.put(multipleDouble, asArray(1.1d * position, 2.2d * position));
properties.put(singleInteger, 1 * position);
properties.put(multipleInteger, asArray(1 * position, 2 * position));
properties.put(singleLong, 1l * position);
properties.put(multipleLong, asArray(1l * position, 2l * position));
GregorianCalendar cal = new GregorianCalendar();
cal.setTime(new Date());
cal.add(Calendar.DAY_OF_MONTH, position);
Date d1 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, -1);
// Date d0 = cal.getTime();
cal.add(Calendar.DAY_OF_MONTH, 2);
Date d2 = cal.getTime();
properties.put(singleDate, d1);
properties.put(multipleDate, asArray(d1, d2));
properties.put(singleDatetime, d1);
properties.put(multipleDatetime, asArray(d1, d2));
properties.put(singleBoolean, position % 2 == 0 ? true : false);
properties.put(multipleBoolean, asArray(true, false));
NodeRef c0 = nodeService.createNode(f0, ContentModel.ASSOC_CONTAINS, QName.createQName("cm", "Test One", namespaceService), extendedContent, properties).getChildRef();
return c0;
}