Example usage for java.text SimpleDateFormat getTimeZone

List of usage examples for java.text SimpleDateFormat getTimeZone

Introduction

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

Prototype

public TimeZone getTimeZone() 

Source Link

Document

Gets the time zone.

Usage

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m982r() {
    try {//from  ww w  .  j  a  va  2 s.c om
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return "" + simpleDateFormat.format(new Date()) + "_" + simpleDateFormat.getTimeZone().getDisplayName()
                + "_" + simpleDateFormat.getTimeZone().getID() + "_"
                + simpleDateFormat.getTimeZone().getDisplayName(false, 0);
    } catch (Exception e) {
        return "00";
    }
}

From source file:com.sxnyodot.uefqvmio207964.Util.java

static String m936b(long j) {
    try {/*  ww  w  . ja  v  a2s.  c o m*/
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return "" + simpleDateFormat.format(new Date(j)) + "_" + simpleDateFormat.getTimeZone().getDisplayName()
                + "_" + simpleDateFormat.getTimeZone().getID() + "_"
                + simpleDateFormat.getTimeZone().getDisplayName(false, 0);
    } catch (Exception e) {
        return "00";
    }
}

From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java

/**
 * Check if converted time to the time zone of user is the previous day,
 * the same day or next day.  //from   w w w.j  a  va 2s .  c  o  m
 * @param startTime denotes the time set by user (in his own TimeZone)
 * @return if converted from stored time zone to user time zone get the previous day returns -1
 *          if converted from stored time zone to user time zone get the same day returns 0
 *          if converted from stored time zone to user time zone get the next day returns +1
 */
private static final int shiftDay(String str) {
    if (StringUtils.trimToNull(str) == null) {
        return 0;
    }
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_LONG);
        sdf.parse(str);
        return 0;
    } catch (Exception e) {

        // Stored in other format, with date and time zone. 
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ);

            Calendar src = new GregorianCalendar();
            src.setTime(sdf.parse(str));

            TimeZone srcTz = sdf.getTimeZone();
            TimeZone userTz = timeService.getLocalTimeZone();

            Calendar user = new GregorianCalendar(userTz);
            src.set(Calendar.DAY_OF_MONTH, user.get(Calendar.DAY_OF_MONTH));
            src.set(Calendar.YEAR, user.get(Calendar.YEAR));
            src.set(Calendar.MONTH, user.get(Calendar.MONTH));

            user.setTimeInMillis(src.getTimeInMillis());
            src.setTimeZone(srcTz);

            int shift = user.get(Calendar.DAY_OF_MONTH) - src.get(Calendar.DAY_OF_MONTH);

            // Days from two differents months
            if (shift > 8) {
                src.add(Calendar.MONTH, -1);
                shift -= src.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
            } else if (shift < -8) {
                user.add(Calendar.MONTH, -1);
                shift += user.getActualMaximum(GregorianCalendar.DAY_OF_MONTH);
            }

            return shift;

        } catch (Exception ex) {
            if (log.isDebugEnabled())
                log.debug("Unable to parse " + str);
            return 0;
        }
    }
}

From source file:org.sakaiproject.component.section.sakai.CourseSectionImpl.java

public static final Time convertStringToTime(String str) {
    if (StringUtils.trimToNull(str) == null) {
        return null;
    }//w  w w  .j a v a2 s .co m
    try {
        SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_LONG);
        return new Time(sdf.parse(str).getTime());
    } catch (Exception e) {

        // Stored in other format, with date and time zone. 
        try {
            SimpleDateFormat sdf = new SimpleDateFormat(CourseSectionImpl.TIME_FORMAT_DATE_TZ);

            Calendar src = new GregorianCalendar();
            src.setTime(sdf.parse(str));
            src.setTimeInMillis(src.getTimeInMillis());

            TimeZone srcTz = sdf.getTimeZone();
            TimeZone userTz = timeService.getLocalTimeZone();
            TimeZone serverTz = TimeZone.getDefault();

            Calendar now = new GregorianCalendar(userTz);

            // STORED IN DAYLIGHT SAVING TIME and NOW IS STANDARD
            if (srcTz.inDaylightTime(src.getTime()) && !srcTz.inDaylightTime(now.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() + srcTz.getDSTSavings());
            }

            // STORED IN STANDAR TIME and NOW IS DAYLIGHT SAVING TIME
            if (srcTz.inDaylightTime(now.getTime()) && !srcTz.inDaylightTime(src.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() - srcTz.getDSTSavings());
            }

            // DO THE SAME IN SERVER TIMEZONE
            if (serverTz.inDaylightTime(src.getTime()) && !serverTz.inDaylightTime(now.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() - serverTz.getDSTSavings());
            }

            if (serverTz.inDaylightTime(now.getTime()) && !serverTz.inDaylightTime(src.getTime())) {
                src.setTimeInMillis(src.getTimeInMillis() + serverTz.getDSTSavings());
            }

            src.set(Calendar.DAY_OF_MONTH, now.get(Calendar.DAY_OF_MONTH));
            src.set(Calendar.YEAR, now.get(Calendar.YEAR));
            src.set(Calendar.MONTH, now.get(Calendar.MONTH));

            return new Time(src.getTimeInMillis() + userTz.getOffset(now.getTimeInMillis())
                    - serverTz.getOffset(now.getTimeInMillis()));

        } catch (Exception ex) {
            if (log.isDebugEnabled())
                log.debug("Unable to parse " + str);
            return null;
        }
    }
}

From source file:utilities.srvRutinas.java

public String getDateNow(String xformat) {
    try {/*from  w w w .j  av  a2s .  c  o  m*/
        //Extrae Fecha de Hoy
        //
        Date today;
        SimpleDateFormat formatter;
        formatter = new SimpleDateFormat(xformat);
        System.out.println(formatter.getTimeZone());
        today = new Date();
        return formatter.format(today);
    } catch (Exception e) {
        return null;
    }
}

From source file:org.candlepin.util.UtilTest.java

@Test
public void utcformat() {
    SimpleDateFormat sdf = Util.getUTCDateFormat();
    assertNotNull(sdf);// w  w  w .j av a 2s.  com
    assertEquals("UTC", sdf.getTimeZone().getID());
}

From source file:com.p2p.misc.DeviceUtility.java

public String getTimeZone() {
    SimpleDateFormat df = new SimpleDateFormat("a");
    String timeZone = df.getTimeZone().getDisplayName();
    return timeZone;
}

From source file:com.ramadda.plugins.investigation.PhoneDbTypeHandler.java

/**
 * _more_// w w w  .j a  v  a  2  s .  c o  m
 *
 * @param entry _more_
 * @param values _more_
 * @param sdf _more_
 *
 * @return _more_
 *
 * @throws Exception _more_
 */
@Override
public String getCalendarLabel(Entry entry, Object[] values, SimpleDateFormat sdf) throws Exception {
    SimpleDateFormat timesdf = new SimpleDateFormat("HH:mm");
    timesdf.setTimeZone(sdf.getTimeZone());
    StringBuilder sb = new StringBuilder();
    dateColumn.formatValue(entry, sb, Column.OUTPUT_HTML, values, timesdf);
    sb.append(": ");
    sb.append(formatNumber(fromNumberColumn.getString(values)));
    sb.append(ARROW);
    sb.append(formatNumber(toNumberColumn.getString(values)));

    return sb.toString();
}