java.util.GregorianCalendar#setTime ( )源码实例Demo

下面列出了java.util.GregorianCalendar#setTime ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rdf4j   文件: LiteralsTest.java
/**
 * Test method for
 * {@link org.eclipse.rdf4j.model.util.Literals#createLiteralOrFail(org.eclipse.rdf4j.model.ValueFactory, java.lang.Object)}
 * .
 */
@Test
public void testCreateLiteralOrFailObjectXMLGregorianCalendar() throws Exception {

	GregorianCalendar c = new GregorianCalendar();
	c.setTime(new Date());
	try {
		Object obj = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
		Literal l = Literals.createLiteralOrFail(SimpleValueFactory.getInstance(), obj);
		assertNotNull(l);
		assertEquals(l.getDatatype(), XMLSchema.DATETIME);
		// TODO check lexical value?
	} catch (DatatypeConfigurationException e) {
		e.printStackTrace();
		fail("Could not instantiate javax.xml.datatype.DatatypeFactory");
	}

}
 
源代码2 项目: AppleCommander   文件: AppleUtil.java
/**
 * Set a ProDOS date into the buffer.
 */
public static void setProdosDate(byte[] buffer, int offset, Date date) {
	int day = 0;
	int month = 0;
	int year = 0;
	int minute = 0;
	int hour = 0;
	if (date != null) {
		GregorianCalendar gc = new GregorianCalendar();
		gc.setTime(date);
		day = gc.get(Calendar.DAY_OF_MONTH);
		month = gc.get(Calendar.MONTH) + 1;
		year = gc.get(Calendar.YEAR);
		minute = gc.get(Calendar.MINUTE);
		hour = gc.get(Calendar.HOUR_OF_DAY);
		if (year >= 2000) {
			year -= 2000;
		} else {
			year -= 1900;
		}
	}
	int ymd = ((year & 0x7f) << 9) | ((month & 0xf) << 5) | (day & 0x1f);
	int hm = ((hour & 0x1f) << 8) | (minute & 0x3f);
	setWordValue(buffer, offset, ymd);
	setWordValue(buffer, offset+2, hm);
}
 
源代码3 项目: openemm   文件: ScriptHelper.java
/**
 * Parse a given date string to a GregorianCalendar
 *
 * @param dateValue
 * @param datePattern
 * @return
 */
public GregorianCalendar parseDate(final String dateValue, final String datePattern) {

	/*
	 * **************************************************
	 *   IMPORTANT  IMPORTANT    IMPORTANT    IMPORTANT
	 * **************************************************
	 *
	 * DO NOT REMOVE METHOD OR CHANGE SIGNATURE!!!
	 */

	try {
		final GregorianCalendar returnValue = new GregorianCalendar();
		final Date parsedDate = new SimpleDateFormat(datePattern).parse(dateValue);
		returnValue.setTime(parsedDate);
		return returnValue;
	} catch (final ParseException e) {
		return null;
	}
}
 
源代码4 项目: openjdk-jdk9   文件: CalendarRegression.java
/**
 * GregorianCalendar handling of Dates Long.MIN_VALUE and Long.MAX_VALUE is
 * confusing; unless the time zone has a raw offset of zero, one or the
 * other of these will wrap.  We've modified the test given in the bug
 * report to therefore only check the behavior of a calendar with a zero raw
 * offset zone.
 */
public void Test4145158() {
    GregorianCalendar calendar = new GregorianCalendar();

    calendar.setTimeZone(TimeZone.getTimeZone("GMT"));

    calendar.setTime(new Date(Long.MIN_VALUE));
    int year1 = calendar.get(YEAR);
    int era1 = calendar.get(ERA);

    calendar.setTime(new Date(Long.MAX_VALUE));
    int year2 = calendar.get(YEAR);
    int era2 = calendar.get(ERA);

    if (year1 == year2 && era1 == era2) {
        errln("Fail: Long.MIN_VALUE or Long.MAX_VALUE wrapping around");
    }
}
 
源代码5 项目: openemm   文件: DateUtil.java
public static boolean isValidSendDate( Date sendDate) {
	// Create the calendar object for comparison
    GregorianCalendar now = new GregorianCalendar();
    GregorianCalendar sendDateCalendar = new GregorianCalendar();

    // Set the time of the test-calendar
    sendDateCalendar.setTime( sendDate);

    // Move "current time" 5 minutes into future, so we get a 5 minute fairness period
    now.add( Calendar.MINUTE, -5);
    
    // Do the hard work!
    return now.before( sendDateCalendar);
}
 
源代码6 项目: nebula   文件: DayModel_GetColumnsForEventsTest.java
private Date time(int hour, int minutes) {
	GregorianCalendar gc = new GregorianCalendar();
	gc.setTime(new Date());
	gc.set(Calendar.HOUR_OF_DAY, hour);
	gc.set(Calendar.MINUTE, minutes);
	return gc.getTime();
}
 
源代码7 项目: BigDataPlatform   文件: TimeUtil.java
/**
 * 获取今年是哪一年
 * @return
 */
public static Integer getNowYear() {
    Date date = new Date();
    GregorianCalendar gc = (GregorianCalendar) Calendar.getInstance();
    gc.setTime(date);
    return Integer.valueOf(gc.get(1));
}
 
源代码8 项目: freehealth-connector   文件: SealedProcessor.java
public static XMLGregorianCalendar getXMLGregorianCalendar (Date dateValue) {
	XMLGregorianCalendar dateTime = null;
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateValue);
		DatatypeFactory df;
		df = DatatypeFactory.newInstance();
		dateTime = df.newXMLGregorianCalendar(calendar);
	} catch (DatatypeConfigurationException e) {
		//printStackTrace(e,startTimeStamp,procedure,info);
	}
	return dateTime;
}
 
源代码9 项目: ldp4j   文件: DatatypeTest.java
@Test
public void testForValue() throws Exception {
	checkForValue(-1);
	checkForValue(1);
	checkForValue(2l);
	checkForValue(-2l);
	checkForValue(123123123123111232l);
	checkForValue(3.0d);
	checkForValue(4.0f);
	checkForValue((short)5);
	checkForValue((short)2000);
	checkForValue((short)-5);
	checkForValue((byte)6);
	checkForValue(true);
	checkForValue(URI.create("http://www.example.org"));
	checkForValue("test");
	checkForValue(new String[]{"test","test2"});
	checkForValue(BigDecimal.ONE);
	checkForValue(BigInteger.ONE);
	checkForValue(BigInteger.ZERO);
	checkForValue(BigInteger.valueOf(-1));
	checkForValue(new QName("http://www.example.org#","name"));
	checkForValue(DatatypeFactory.newInstance().newDuration(23));
	GregorianCalendar gc=new GregorianCalendar();
	gc.setTime(new Date());
	checkForValue(DatatypeFactory.newInstance().newXMLGregorianCalendar(gc));
}
 
源代码10 项目: activiti6-boot2   文件: DefaultJobManager.java
protected JobEntity internalCreateLockedAsyncJob(ExecutionEntity execution, boolean exclusive) {
  JobEntity asyncJob = processEngineConfiguration.getJobEntityManager().create();
  fillDefaultAsyncJobInfo(asyncJob, execution, exclusive);
  
  GregorianCalendar gregorianCalendar = new GregorianCalendar();
  gregorianCalendar.setTime(processEngineConfiguration.getClock().getCurrentTime());
  gregorianCalendar.add(Calendar.MILLISECOND, getAsyncExecutor().getAsyncJobLockTimeInMillis());
  asyncJob.setLockExpirationTime(gregorianCalendar.getTime());
  asyncJob.setLockOwner(getAsyncExecutor().getLockOwner());
  
  return asyncJob;
}
 
源代码11 项目: AppleCommander   文件: AppleUtil.java
/**
  * Set a Pascal data to 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 void setPascalDate(byte[] buffer, int offset, Date date) {
	GregorianCalendar gc = new GregorianCalendar();
	gc.setTime(date);
	int month = gc.get(Calendar.MONTH) + 1;
	int day = gc.get(Calendar.DAY_OF_MONTH);
	int year = gc.get(Calendar.YEAR) % 100;
	int pascalDate = (month & 0x000f)
		| ((day << 4) & 0x01f0)
		| ((year << 9) & 0xfe00);
	setWordValue(buffer, offset, pascalDate);
}
 
源代码12 项目: flowable-engine   文件: ExecutionEntity.java
protected void scheduleAtomicOperationAsync(AtomicOperation executionOperation) {
    JobEntity message = new JobEntity();
    message.setJobType(Job.JOB_TYPE_MESSAGE);
    message.setRevision(1);
    message.setExecution(this);
    message.setExclusive(getActivity().isExclusive());
    message.setJobHandlerType(AsyncContinuationJobHandler.TYPE);
    // At the moment, only AtomicOperationTransitionCreateScope can be performed asynchronously,
    // so there is no need to pass it to the handler

    ProcessEngineConfiguration processEngineConfig = Context.getCommandContext().getProcessEngineConfiguration();

    if (processEngineConfig.getAsyncExecutor().isActive()) {
        GregorianCalendar expireCal = new GregorianCalendar();
        expireCal.setTime(processEngineConfig.getClock().getCurrentTime());
        expireCal.add(Calendar.SECOND, processEngineConfig.getLockTimeAsyncJobWaitTime());
        message.setLockExpirationTime(expireCal.getTime());
    }

    // Inherit tenant id (if applicable)
    if (getTenantId() != null) {
        message.setTenantId(getTenantId());
    }

    callJobProcessors(JobProcessorContext.Phase.BEFORE_CREATE, message, Context.getProcessEngineConfiguration());
    Context.getCommandContext().getJobEntityManager().send(message);
}
 
源代码13 项目: activiti6-boot2   文件: AcquireTimerJobsCmd.java
protected void lockJob(CommandContext commandContext, TimerJobEntity job, int lockTimeInMillis) {
  
  // This will trigger an optimistic locking exception when two concurrent executors 
  // try to lock, as the revision will not match.
  
  GregorianCalendar gregorianCalendar = new GregorianCalendar();
  gregorianCalendar.setTime(commandContext.getProcessEngineConfiguration().getClock().getCurrentTime());
  gregorianCalendar.add(Calendar.MILLISECOND, lockTimeInMillis);
  job.setLockOwner(asyncExecutor.getLockOwner());
  job.setLockExpirationTime(gregorianCalendar.getTime());
}
 
源代码14 项目: database-transform-tool   文件: DateUtil.java
/**
 * <pre>
 * 描述:间隔指定天数后日期(例如:每3天)
 * 作者:ZhangYi
 * 时间:2016年5月5日 下午4:29:07
 * 参数:(参数列表)
 * @param dateTime	指定日期
 * @param interval	间隔天数
 * @return
 * </pre>
 */
public static Date handleDateTimeByDay(Date dateTime, int interval) {
	try {
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(dateTime);
		calendar.add(Calendar.DAY_OF_MONTH, interval);
		dateTime = calendar.getTime();
	} catch (Exception e) {
		logger.error("--间隔指定天数后日期异常!", e);
	}
	return dateTime;
}
 
源代码15 项目: arcusplatform   文件: TestUtils.java
public static boolean verifyDate(int expYear, int expMonth, int expDay, int expHour, int expMin, int expSec, Date value) {
   GregorianCalendar gc = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
   gc.setTime(value);
   // 2015-04-23T18:23:09.123
   return ((expYear == gc.get(Calendar.YEAR)) &&
         (expMonth - 1 == gc.get(Calendar.MONTH)) &&
         (expDay == gc.get(Calendar.DAY_OF_MONTH)) &&
         (expHour == gc.get(Calendar.HOUR_OF_DAY)) &&
         (expMin == gc.get(Calendar.MINUTE)) &&
         (expSec == gc.get(Calendar.SECOND)));
}
 
源代码16 项目: open-ig   文件: XElement.java
/**
 * Convert the given date to string.
 * Always contains the milliseconds and timezone.
 * @param date the date, not null
 * @return the formatted date
 */
public static String formatDateTime(Date date) {
	StringBuilder b = new StringBuilder(24);
	
	GregorianCalendar cal = XSD_CALENDAR.get();
	cal.setTime(date);
	
	int value;
	
	// Year-Month-Day
	value = cal.get(GregorianCalendar.YEAR);
	b.append(value);
	b.append('-');
	value = cal.get(GregorianCalendar.MONTH) + 1;
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	b.append('-');
	value = cal.get(GregorianCalendar.DATE);
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	
	b.append('T');
	// hour:minute:second:milliseconds
	value = cal.get(GregorianCalendar.HOUR_OF_DAY);
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	b.append(':');
	value = cal.get(GregorianCalendar.MINUTE);
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	b.append(':');
	value = cal.get(GregorianCalendar.SECOND);
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	b.append('.');
	
	value = cal.get(GregorianCalendar.MILLISECOND);
	// add leading zeros if needed
	if (value < 100) {
		b.append('0');
	}
	if (value < 10) {
		b.append('0');
	}
	b.append(value);
	
	value = cal.get(GregorianCalendar.DST_OFFSET) + cal.get(GregorianCalendar.ZONE_OFFSET);
	
	if (value == 0) {
		b.append('Z');
	} else {
		if (value < 0) {
			b.append('-');
			value = -value;
		} else {
			b.append('+');
		}
		int hour = value / 3600000;
		int minute = value / 60000 % 60;
		if (hour < 10) {
			b.append('0');
		}
		b.append(hour);
		b.append(':');
		if (minute < 10) {
			b.append('0');
		}
		b.append(minute);
	}
	
	
	return b.toString();
}
 
源代码17 项目: teaching   文件: DateUtils.java
public static int getYear() {
    GregorianCalendar calendar = new GregorianCalendar();
    calendar.setTime(getDate());
    return calendar.get(Calendar.YEAR);
}
 
源代码18 项目: openbd-core   文件: Date.java
public static GregorianCalendar createCalendar(long timeMS) {
	GregorianCalendar G = new GregorianCalendar();
	G.setTime(new java.util.Date(timeMS));
	return G;
}
 
源代码19 项目: openemm   文件: DateUtilities.java
public static Date getDateOfHoursAgo(Date initDate, int hoursAgo) {
GregorianCalendar returnDate = new GregorianCalendar();
returnDate.setTime(initDate);
returnDate.add(Calendar.HOUR, -hoursAgo);
return returnDate.getTime();
  }
 
源代码20 项目: java-client-api   文件: ExtractRowsViaTemplate.java
public void setup() throws ParseException, IOException {
  // insert a sample MarkLogic template which can extract fields from the
  // sample data below
  ObjectMapper mapper = new ObjectMapper()
    .configure(Feature.ALLOW_SINGLE_QUOTES, true);
  docMgr.writeAs(templateUri, mapper.readTree(
    "{ 'template':{ 'description':'test template', 'context':'/firstName', " +
    "    'rows':[ { 'schemaName':'employee', 'viewName':'employee'," +
    "      'columns':[ { 'name':'firstName', 'scalarType':'string', 'val':'.' }," +
    "                  { 'name':'salary', 'scalarType':'int', 'nullable':true," +
    "                    'val':'max(../salaries/salary)'}" +
    " ] } ] } }"));

  // insert some sample documents
  String[][] employees = new String[][] {
    {"1", "1990-10-04", "Alice", "Edward", "FEMALE", "2012-04-05", "70675"},
    {"2", "1992-12-23", "Bob", "Miller", "MALE", "2010-06-01", "98023"},
    {"3", "1985-11-30", "Gerard", "Steven", "MALE", "2011-07-29", "87455"},
    {"4", "1970-01-08", "Evelyn", "Erick", "FEMALE", "2012-08-24", "62444"},
    {"5", "1978-05-14", "Daniel", "Washington", "MALE", "2007-02-17", "68978,76543,86732"},
    {"6", "1989-07-19", "Eve", "Alfred", "FEMALE", "2009-08-14", "70987,79083"},
    {"7", "1990-09-29", "Rachel", "Fisher", "FEMALE", "2015-01-01", "50678"},
    {"8", "1987-10-26", "Bruce", "Wayne", "MALE", "2010-04-09", "99873,106742"},
    {"9", "1992-11-25", "Thomas", "Crook", "MALE", "2013-07-07", "79003"},
    {"10", "1994-12-04", "Diana", "Trevor", "FEMALE", "2016-09-23", "67893,67993"}
  };
  for ( String[] employee : employees ) {
    Employee newEmployee = new Employee();
    newEmployee.setEmployeeId(Integer.parseInt(employee[0]));
    GregorianCalendar bday = new GregorianCalendar();
    bday.setTime(df.parse(employee[1]));
    newEmployee.setBirthDate(bday);
    newEmployee.setFirstName(employee[2]);
    newEmployee.setLastName(employee[3]);
    newEmployee.setGender(Gender.valueOf(employee[4]));
    ArrayList<Salary> salaries = new ArrayList<>();
    for ( String salary : employee[6].split(",") ) {
      Salary newSalary = new Salary();
      newSalary.setSalary(Integer.parseInt(salary));
      salaries.add(newSalary);
    }
    newEmployee.setSalaries(salaries.toArray(new Salary[salaries.size()]));
    docMgr.writeAs("/employees/" + employee[0] + ".json", newEmployee);
  }
}