List of usage examples for java.util TimeZone getDefault
public static TimeZone getDefault()
From source file:cc.kune.core.server.init.DatabaseInitializer.java
/** * Creates the def users group.//from w ww . j a v a 2 s . co m * * @throws Exception * the exception * @throws UserMustBeLoggedException * the user must be logged exception */ private void createDefUsersGroup() throws Exception, UserMustBeLoggedException { final String adminName = properties.getAdminUserName(); final String adminShortName = properties.getAdminShortName(); final String adminEmail = properties.getAdminEmail(); final String adminPassword = properties.getAdminPassword(); final PasswordDigest passwdDigest = new PasswordDigest(adminPassword.toCharArray()); userManager.createWaveAccount(adminShortName, passwdDigest); final User user = new User(adminShortName, adminName, adminEmail, passwdDigest.getDigest(), passwdDigest.getSalt(), languageManager.findByCode("en"), countryManager.findByCode("GB"), TimeZone.getDefault()); groupManager.createUserGroup(user, false); final User dummyUser = new User("dummy", "dummy user", "example@example.com", passwdDigest.getDigest(), passwdDigest.getSalt(), languageManager.findByCode("en"), countryManager.findByCode("GB"), TimeZone.getDefault()); groupManager.createUserGroup(dummyUser, false); final String siteName = properties.getDefaultSiteName(); final String siteShortName = properties.getDefaultSiteShortName(); final String defaultLicenseId = properties.getDefaultLicense(); final License defaultLicense = licenseManager.findByShortName(defaultLicenseId); final Group siteGroup = new Group(siteShortName, siteName, defaultLicense, GroupType.PROJECT); groupManager.createGroup(siteGroup, user, ContentConstants.INITIAL_CONTENT.replaceAll("\\[%s\\]", siteName)); final Content defaultContent = siteGroup.getDefaultContent(); contentManager.setStatus(defaultContent.getId(), ContentStatus.publishedOnline); contentManager.save(defaultContent); // This is not necessary with ehcache (I think). Even worst, the // initialization hangs // userManager.reIndex(); // groupManager.reIndex(); }
From source file:illab.nabal.util.Util.java
/** * Get system timezone setting.//w w w .j a v a 2 s .c o m * * @return TimeZone */ public static TimeZone getSystemTimeZone() { return TimeZone.getTimeZone(TimeZone.getDefault().getID()); }
From source file:org.appverse.web.framework.backend.batch.services.business.impl.live.JobRunnerServiceImpl.java
private boolean skipExecution(String jobName, int postExecutionSleepTime) { Date startDate = null;/* w w w .j a va2s . co m*/ List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1); if (CollectionUtils.isNotEmpty(jobInstances)) { // This will retrieve the latest job execution: List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstances.get(0)); if (CollectionUtils.isNotEmpty(jobExecutions)) { JobExecution jobExecution = jobExecutions.get(0); startDate = jobExecution.getStartTime(); Long lastExecutionOffsetAsString = (Long) jobExecution.getExecutionContext().get("offset"); long lastExecutionOffset = 0; if (lastExecutionOffsetAsString != null) { lastExecutionOffset = lastExecutionOffsetAsString.longValue(); } else { lastExecutionOffset = TimeZone.getDefault().getOffset(new Date().getTime()); } Date currentDate = new Date(); long offset = TimeZone.getDefault().getOffset(new Date().getTime()); if (startDate != null && currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset) < postExecutionSleepTime * 1000) { logger.debug("Current date offset " + offset); logger.debug("Current date with offset " + (currentDate.getTime() - offset)); logger.debug("Last execution date offset " + lastExecutionOffset); logger.debug("Last execution date with offset " + (startDate.getTime() - lastExecutionOffset)); logger.debug("Current date with offset - start date with offset " + (currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset))); logger.info("Batch executed " + (currentDate.getTime() - offset - (startDate.getTime() - lastExecutionOffset)) / 60000 + " minutes before"); logger.info("Batch run skipped "); return true; } } } logger.info("Batch run started "); return false; }
From source file:com.indoqa.lang.util.TimeUtils.java
public static Date getStartOfDay(Date date) { return getStartOfDay(date, TimeZone.getDefault()); }
From source file:at.bitfire.davdroid.ui.CreateCalendarActivity.java
@Override public void onLoadFinished(Loader<AccountInfo> loader, AccountInfo info) { Spinner spinner = (Spinner) findViewById(R.id.time_zone); String[] timeZones = TimeZone.getAvailableIDs(); spinner.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, timeZones)); // select system time zone String defaultTimeZone = TimeZone.getDefault().getID(); for (int i = 0; i < timeZones.length; i++) if (timeZones[i].equals(defaultTimeZone)) { spinner.setSelection(i);/*from ww w . j a v a 2 s.c o m*/ break; } if (info != null) { spinner = (Spinner) findViewById(R.id.home_sets); spinner.setAdapter( new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, info.homeSets)); } }
From source file:dk.teachus.backend.testdatagenerator.DynamicDataImport.java
private void createTeacherAttribute(Teacher teacher) { Session session = sessionFactory.openSession(); session.beginTransaction();/*from ww w . ja va 2 s . co m*/ TeacherAttribute attribute = new WelcomeIntroductionTeacherAttribute(); attribute.setTeacher(teacher); attribute.setValue("A welcome introduction"); session.save(attribute); TimeZoneAttribute tzAttribute = new TimeZoneAttribute(); tzAttribute.setTeacher(teacher); tzAttribute.setTimeZone(TimeZone.getDefault()); session.save(tzAttribute); session.getTransaction().commit(); session.close(); }
From source file:com.augmentum.common.util.DateUtil.java
public static int getDaysBetween(Date startDate, Date endDate) { return getDaysBetween(startDate, endDate, TimeZone.getDefault()); }
From source file:com.exadel.flamingo.flex.messaging.amf.io.AMF0Serializer.java
/** * Writes Data/*from w w w .j ava2s . c om*/ * * @param value * @throws java.io.IOException */ protected void writeData(Object value) throws IOException { if (value == null) { // write null object outputStream.writeByte(AMF0Body.DATA_TYPE_NULL); } else if (value instanceof AMF3Object) { writeAMF3Data((AMF3Object) value); } else if (isPrimitiveArray(value)) { writePrimitiveArray(value); } else if (value instanceof Number) { // write number object outputStream.writeByte(AMF0Body.DATA_TYPE_NUMBER); outputStream.writeDouble(((Number) value).doubleValue()); } else if (value instanceof String) { writeString((String) value); } else if (value instanceof Character) { // write String object outputStream.writeByte(AMF0Body.DATA_TYPE_STRING); outputStream.writeUTF(value.toString()); } else if (value instanceof Boolean) { // write boolean object outputStream.writeByte(AMF0Body.DATA_TYPE_BOOLEAN); outputStream.writeBoolean(((Boolean) value).booleanValue()); } else if (value instanceof Date) { // write Date object outputStream.writeByte(AMF0Body.DATA_TYPE_DATE); outputStream.writeDouble(((Date) value).getTime()); int offset = TimeZone.getDefault().getRawOffset(); outputStream.writeShort(offset / MILLS_PER_HOUR); } else { if (storedObjects.containsKey(value)) { writeStoredObject(value); return; } storeObject(value); if (value instanceof Object[]) { // write Object Array writeArray((Object[]) value); } else if (value instanceof Iterator) { write((Iterator<?>) value); } else if (value instanceof Collection) { write((Collection<?>) value); } else if (value instanceof Map) { writeMap((Map<?, ?>) value); } else if (value instanceof ResultSet) { ASRecordSet asRecordSet = new ASRecordSet(); asRecordSet.populate((ResultSet) value); writeData(asRecordSet); } else if (value instanceof Document) { write((Document) value); } else { /* MM's gateway requires all objects to be marked with the Serializable interface in order to be serialized That should still be followed if possible, but there is no good reason to enforce it. */ writeObject(value); } } }
From source file:figs.treeVisualization.gui.PhyloDateAxis.java
/** * Returns the previous "standard" date, for a given date and tick unit. * * @param date the reference date.//from w w w .j av a 2 s .c o m * @param unit the tick unit. * * @return The previous "standard" date. */ @Override protected Date previousStandardDate(Date date, DateTickUnit unit) { int hours; int days; int months; int years; Calendar calendar = Calendar.getInstance(TimeZone.getDefault()); calendar.setTime(getMinimumDate()); int current = calendar.get(unit.getCalendarField()); // We only care about DAY, MONTH, YEAR DateTickMarkPosition tickMarkPosition = this.getTickMarkPosition(); switch (unit.getUnit()) { case (DateTickUnit.DAY): years = calendar.get(Calendar.YEAR); months = calendar.get(Calendar.MONTH); if (tickMarkPosition == DateTickMarkPosition.START) { hours = 0; } else if (tickMarkPosition == DateTickMarkPosition.MIDDLE) { hours = 12; } else { hours = 23; } calendar.clear(Calendar.MILLISECOND); calendar.set(years, months, current, hours, 0, 0); long result = calendar.getTime().getTime(); if (result > date.getTime()) { // move it back a day calendar.set(years, months, current - 1, hours, 0, 0); } return calendar.getTime(); case (DateTickUnit.MONTH): years = calendar.get(Calendar.YEAR); calendar.clear(Calendar.MILLISECOND); calendar.set(years, current, 1, 0, 0, 0); // TODO: /* Month month = new Month(calendar.getTime()); Date standardDate = calculateDateForPosition( month, tickMarkPosition ); long millis = standardDate.getTime(); if (millis > date.getTime()) { month = (Month) month.previous(); standardDate = calculateDateForPosition( month, tickMarkPosition ); } return standardDate; */ return calendar.getTime(); case (DateTickUnit.YEAR): if (tickMarkPosition == DateTickMarkPosition.START) { months = 0; days = 1; } else if (tickMarkPosition == DateTickMarkPosition.MIDDLE) { months = 6; days = 1; } else { months = 11; days = 31; } calendar.clear(Calendar.MILLISECOND); calendar.set(current, months, days, 0, 0, 0); return calendar.getTime(); default: return calendar.getTime(); } }
From source file:com.saysth.commons.quartz.CronTriggerBean.java
public void afterPropertiesSet() throws Exception { if (this.startDelay > 0) { setStartTime(new Date(System.currentTimeMillis() + this.startDelay)); }// w w w.ja v a 2 s .co m if (getName() == null) { setName(this.beanName); } if (getGroup() == null) { setGroup(Scheduler.DEFAULT_GROUP); } if (getStartTime() == null) { setStartTime(new Date()); } if (getTimeZone() == null) { setTimeZone(TimeZone.getDefault()); } if (this.jobDetail != null) { setJobName(this.jobDetail.getKey().getName()); setJobGroup(this.jobDetail.getKey().getGroup()); } }