Example usage for java.text SimpleDateFormat setTimeZone

List of usage examples for java.text SimpleDateFormat setTimeZone

Introduction

In this page you can find the example usage for java.text SimpleDateFormat setTimeZone.

Prototype

public void setTimeZone(TimeZone zone) 

Source Link

Document

Sets the time zone for the calendar of this DateFormat object.

Usage

From source file:com.persistent.cloudninja.scheduler.Scheduler.java

/**
 * Register a task in TaskSchedule table.
 * /*from   w w w . j a va 2  s.co  m*/
 * @param taskId : ID of task.
 * @param frequencyInMin : frequency in minutes.
 */
private void registerTask(String taskId, long frequencyInMin) {
    try {
        TaskScheduleEntity taskScheduleEntity = new TaskScheduleEntity();
        taskScheduleEntity.setTaskId(taskId);
        taskScheduleEntity.setFrequency(frequencyInMin);

        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.SECOND, (int) frequencyInMin * 60);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String nextScheduledStartTime = dateFormat.format(calendar.getTime());

        taskScheduleEntity.setNextScheduledStartTime(dateFormat.parse(nextScheduledStartTime));
        taskScheduleDao.updateTaskSchedule(taskScheduleEntity);
        taskList.add(taskId);

        storageUtility.initializeQueue(TASK_SCHEDULER_PREFIX + taskId.toLowerCase());
    } catch (ParseException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (URISyntaxException e) {
        LOGGER.error(e.getMessage(), e);
    } catch (StorageException e) {
        LOGGER.error(e.getMessage(), e);
    }
}

From source file:nz.net.orcon.kanban.automation.AutomationEngineTestIT.java

@Test
public void testEvalProperty_time() {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    df.applyLocalizedPattern("yyyy-MM-dd'T'HH:mm:ss.SSS");

    Date date = new Date();

    String time1 = "xs:dateTime('" + df.format(date) + "+00:00')";
    System.out.println(time1);/*w ww  .j a v a 2 s . co m*/
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    String time = "xs:dateTime('" + df.format(date) + "+00:00')";
    System.out.println(time);
}

From source file:cn.ctyun.amazonaws.auth.AWS4Signer.java

protected String getDateStamp(Date date) {
    SimpleDateFormat dateStampFormat;
    dateStampFormat = new SimpleDateFormat("yyyyMMdd");
    dateStampFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
    return dateStampFormat.format(date);
}

From source file:com.gae.JsonBeans.java

public String doPut(String mod, Key ekey, String kind, String key, String[] id, String[] val) {
    Entity entity = setentity(mod, ekey, kind, key, id, val);
    Date date = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd:HHmmss");
    sdf.setTimeZone(TimeZone.getTimeZone("JST"));
    entity.setProperty("moddate", date);
    ds.put(entity);/*w ww  .ja va 2s .  c om*/
    if (mod.equals("add")) {
        return ("? KEY:" + key);
    } else {
        return ("? KEY:" + key);
    }
}

From source file:com.yahoo.semsearch.fastlinking.io.EnglishWikipediaPage.java

@Override
protected void processPage(String s) {
    this.language = LANGUAGE_CODE;

    // parse out title
    int start = s.indexOf(XML_START_TAG_TITLE);
    int end = s.indexOf(XML_END_TAG_TITLE, start);
    this.title = StringEscapeUtils.unescapeHtml(s.substring(start + 7, end)).trim();

    // determine if article belongs to the article namespace
    start = s.indexOf(XML_START_TAG_NAMESPACE);
    end = s.indexOf(XML_END_TAG_NAMESPACE);
    this.isArticle = start == -1 ? true : s.substring(start + 4, end).trim().equals("0");
    // add check because namespace tag not present in older dumps

    // parse out the document id
    start = s.indexOf(XML_START_TAG_ID);
    end = s.indexOf(XML_END_TAG_ID);/*from w  w  w. j  a v  a2 s. c om*/
    this.mId = s.substring(start + 4, end);

    // parse out actual text of article
    this.textStart = s.indexOf(XML_START_TAG_TEXT);
    this.textEnd = s.indexOf(XML_END_TAG_TEXT, this.textStart);

    // determine if article is a disambiguation, redirection, and/or stub page.
    //      this.isDisambig = disambPattern.matcher(page).find() || disambPattern2.matcher(this.title).find();
    this.isDisambig = _isDisambiguation(page);

    this.isRedirect = s
            .substring(this.textStart + XML_START_TAG_TEXT.length(),
                    this.textStart + XML_START_TAG_TEXT.length() + IDENTIFIER_REDIRECTION_UPPERCASE.length())
            .compareTo(IDENTIFIER_REDIRECTION_UPPERCASE) == 0
            || s.substring(this.textStart + XML_START_TAG_TEXT.length(),
                    this.textStart + XML_START_TAG_TEXT.length() + IDENTIFIER_REDIRECTION_CAMELCASE.length())
                    .compareTo(IDENTIFIER_REDIRECTION_CAMELCASE) == 0
            || s.substring(this.textStart + XML_START_TAG_TEXT.length(),
                    this.textStart + XML_START_TAG_TEXT.length() + IDENTIFIER_REDIRECTION_LOWERCASE.length())
                    .compareTo(IDENTIFIER_REDIRECTION_LOWERCASE) == 0;

    this.isStub = s.indexOf(IDENTIFIER_STUB_TEMPLATE, this.textStart) != -1
            || s.indexOf(IDENTIFIER_STUB_WIKIPEDIA_NAMESPACE) != -1;

    // get revision
    start = s.indexOf(XML_START_TAG_REVISION);
    end = s.indexOf(XML_END_TAG_REVISION, start);
    this.revision = s.substring(start + 11, end);

    // get revision as Date
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    try {
        this.revisionDate = dateFormat.parse(this.revision);
    } catch (ParseException e) {
        e.printStackTrace();
    }

    // count number of infoboxes
    this.infoboxCount = countObject(s, INFOBOX_CONST_STR);

    // count number of categories
    this.categoryCount = countObject(s, CATEGORY_CONST_STR);

    // count number of citations
    this.citationCount = countObject(s, CITE_CONST_STR);

    String html;

    if (textStart == -1 || textEnd == -1 || textStart + 27 < 0) {
        html = "";
    } else {
        WikiModel wikiModel = new WikiModel("image::", "external::");
        wikiModel.setUp();
        try {
            html = wikiModel.render(s.substring(textStart + 27, textEnd));
            // System.err.println(html);
        } catch (StringIndexOutOfBoundsException e) {
            e.printStackTrace();
            System.err.println(s);
            html = "";
        }
        wikiModel.tearDown();
    }

    // count number of sections
    this.sectionCount = countObject(html, SECTION_CONST_STR);

    // count number of external links
    this.exLinksCount = countExternalLinks(html);

}

From source file:net.bulletin.pdi.xero.step.XeroGetStep.java

private String createIfModifiedSinceHeaderValue(XeroGetStepMeta meta) throws KettleException {
    String ifModifiedSinceAsSupplied = meta.getIfModifiedSince();

    if (StringUtils.isNotBlank(ifModifiedSinceAsSupplied)) {
        ifModifiedSinceAsSupplied = environmentSubstitute(ifModifiedSinceAsSupplied);
        SimpleDateFormat formatInput = new SimpleDateFormat(FORMAT_TIMESTAMP_INPUT);

        try {// w  ww.jav  a2s  .c  o m
            Date ifModifiedSince = formatInput.parse(ifModifiedSinceAsSupplied);
            SimpleDateFormat formatOutput = new SimpleDateFormat(FORMAT_TIMESTAMP_IFMODIFIEDSINCE_XERO);
            formatOutput.setTimeZone(TimeZone.getTimeZone("GMT-0"));
            return formatOutput.format(ifModifiedSince);
        } catch (ParseException pe) {
            throw new KettleException("unable to parse the supplied if-modified-since; "
                    + ifModifiedSinceAsSupplied + " (should be '" + FORMAT_TIMESTAMP_INPUT + "')", pe);
        }
    }

    return null;
}

From source file:cn.ctyun.amazonaws.auth.AWS4Signer.java

protected String getDateTimeStamp(Date date) {
    SimpleDateFormat dateTimeFormat;
    dateTimeFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
    dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
    return dateTimeFormat.format(date);
}

From source file:com.funambol.foundation.items.dao.DataBaseFileDataObjectMetadataDAO.java

private static String utcDateTime(Timestamp timestamp) {

    if (timestamp == null) {
        return null;
    }/*from w w w .j  a  va 2  s .c  o  m*/

    SimpleDateFormat formatter = new SimpleDateFormat(TimeUtils.PATTERN_UTC);
    formatter.setTimeZone(TimeUtils.TIMEZONE_UTC);

    return formatter.format(new Date(timestamp.getTime()));

}

From source file:com.persistent.cloudninja.scheduler.Scheduler.java

/**
 * This method will query the TaskSchedule table to find out the
 * eligible tasks for scheduling.//  www. j  a  v a2  s.  c  om
 * 
 */
@Scheduled(fixedDelay = SchedulerSettings.SchedulerInterval)
public void doSchedule() {
    LOGGER.debug("Start schedule");
    String taskId = "";

    List<TaskScheduleEntity> listTaskSchedule = taskScheduleDao.getTaskScheduledList();

    for (TaskScheduleEntity taskScheduleEntity : listTaskSchedule) {
        try {
            Date nextScheduledTime = taskScheduleEntity.getNextScheduledStartTime();
            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String nextScheduledStartTime = dateFormat.format(calendar.getTime());
            Date currentTime = dateFormat.parse(nextScheduledStartTime);
            if (taskList.contains(taskScheduleEntity.getTaskId())
                    && nextScheduledTime.getTime() < currentTime.getTime()) {
                taskId = taskScheduleEntity.getTaskId();
                String leaseId = "";
                leaseId = acquireLock(taskId);
                LOGGER.debug("doSchedule : lease " + leaseId);
                if (!leaseId.isEmpty()) {
                    try {
                        storageUtility.putMessage(TASK_SCHEDULER_PREFIX + taskId.toLowerCase(), taskId);
                        LOGGER.debug("doSchedule : put message in Q taskscheduler-" + taskId.toLowerCase());

                        calendar = Calendar.getInstance();
                        calendar.add(Calendar.SECOND, (int) taskScheduleEntity.getFrequency() * 60);
                        dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
                        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                        nextScheduledStartTime = dateFormat.format(calendar.getTime());

                        taskScheduleEntity.setNextScheduledStartTime(dateFormat.parse(nextScheduledStartTime));
                        taskScheduleDao.updateTaskSchedule(taskScheduleEntity);

                        storageUtility.releaseLease(taskId, leaseId);
                        LOGGER.debug("doSchedule : lease released");
                    } catch (Exception e) {
                        LOGGER.error(e.getMessage(), e);
                    }
                }
            }
        } catch (ParseException e) {
            LOGGER.error(e.getMessage(), e);
        }

    }
    LOGGER.debug("End schedule");
}

From source file:com.bullmobi.base.ui.fragments.dialogs.FeedbackDialog.java

private void attachLog(@NonNull Intent intent) {
    Context context = getActivity();

    try {/*from  w w  w.j av  a2s  .  co m*/
        String log = Logcat.capture();
        if (log == null)
            throw new Exception("Failed to capture the logcat.");

        // Prepare cache directory.
        File cacheDir = context.getCacheDir();
        if (cacheDir == null)
            throw new Exception("Cache directory is inaccessible");
        File directory = new File(cacheDir, LogsProviderBase.DIRECTORY);
        FileUtils.deleteRecursive(directory); // Clean-up cache folder
        if (!directory.mkdirs())
            throw new Exception("Failed to create cache directory.");

        // Create log file.
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
        sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
        String fileName = "EasyNotification_log_" + sdf.format(new Date()) + ".txt";
        File file = new File(directory, fileName);

        // Write to the file.
        if (!FileUtils.writeToFile(file, log))
            throw new Exception("Failed to write log to the file.");

        // Put extra stream to the intent.
        Uri uri = Uri.parse("content://" + LogAttachmentProvider.AUTHORITY + "/" + fileName);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
    } catch (Exception e) {
        String message = ResUtils.getString(getResources(), R.string.feedback_error_accessing_log,
                e.getMessage());
        ToastUtils.showLong(context, message);
    }
}