Example usage for java.util SimpleTimeZone SimpleTimeZone

List of usage examples for java.util SimpleTimeZone SimpleTimeZone

Introduction

In this page you can find the example usage for java.util SimpleTimeZone SimpleTimeZone.

Prototype

public SimpleTimeZone(int rawOffset, String ID) 

Source Link

Document

Constructs a SimpleTimeZone with the given base time zone offset from GMT and time zone ID with no daylight saving time schedule.

Usage

From source file:org.gogpsproject.parser.rinex.RinexNavigation.java

/**
 * @param args//  w  w  w  . j ava2 s.c  om
 */
public static void main(String[] args) {

    TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

    Calendar c = Calendar.getInstance();
    c.set(Calendar.YEAR, 2011);
    c.set(Calendar.MONTH, 0);
    c.set(Calendar.DAY_OF_MONTH, 9);
    c.set(Calendar.HOUR_OF_DAY, 1);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
    c.setTimeZone(new SimpleTimeZone(0, ""));

    Time t = new Time(c.getTimeInMillis());

    System.out.println("ts: " + t.getMsec() + " " + (new Date(t.getMsec())));
    System.out.println("week: " + t.getGpsWeek());
    System.out.println("week sec: " + t.getGpsWeekSec());
    System.out.println("week day: " + t.getGpsWeekDay());
    System.out.println("week hour in day: " + t.getGpsHourInDay());

    System.out.println("ts2: " + (new Time(t.getGpsWeek(), t.getGpsWeekSec())).getMsec());

    RinexNavigation rn = new RinexNavigation(IGN_NAVIGATION_HOURLY_ZIM2);
    rn.init();
    //      SatellitePosition sp = rn.getGpsSatPosition(c.getTimeInMillis(), 2, 0, 0);
    Observations obs = new Observations(new Time(c.getTimeInMillis()), 0);
    SatellitePosition sp = rn.getGpsSatPosition(obs, 2, 'G', 0);

    if (sp != null) {
        System.out
                .println("found " + (new Date(sp.getUtcTime())) + " " + (sp.isPredicted() ? " predicted" : ""));
    } else {
        System.out.println("Epoch not found " + (new Date(c.getTimeInMillis())));
    }

}

From source file:com.ibm.dgaasx.utils.JSONUtils.java

public static SimpleDateFormat getSDFISO8601() {
    SimpleDateFormat sdf = new ISO8601DateTimeFormat();
    sdf.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC")); //$NON-NLS-1$
    return sdf;/* w  w w. j  a  v a  2 s. c om*/
}

From source file:com.cloudera.api.ApiObjectMapper.java

public static DateFormat makeISODateFormat() {
    DateFormat iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    iso8601.setCalendar(cal);/*w  w  w.  ja v a2  s  .  co m*/
    return iso8601;
}

From source file:com.devicehive.service.time.LocalTimestampService.java

@Override
public String getDateAsString() {
    DATE_FORMAT.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    return DATE_FORMAT.format(getDate());
}

From source file:com.ewcms.common.query.mongo.EasyQueryInit.java

public EasyQueryInit(MongoOperations operations) {
    this.operations = operations;
    format = new SimpleDateFormat("yyyy-MM-dd");
    format.setCalendar(new GregorianCalendar(new SimpleTimeZone(0, "GMT")));

}

From source file:com.cloudera.api.ApiObjectMapper.java

public static DateFormat makeDateFormat(String format) {
    DateFormat dateFormat = new SimpleDateFormat(format);
    Calendar cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
    dateFormat.setCalendar(cal);/*w ww . j  a v  a 2 s  .  c  om*/
    return dateFormat;
}

From source file:srvmonitor.thGetAgendas.java

@Override
public void run() {
    /*/*  w ww . j av a2 s  .co  m*/
    Recupera Parametros Fecha Actual
    */
    logger.info("Buscando Agendas Activas");

    String[] ids = TimeZone.getAvailableIDs(-4 * 60 * 60 * 1000);
    String clt = ids[0];
    SimpleTimeZone tz = new SimpleTimeZone(-4 * 60 * 60 * 1000, clt);
    tz.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    tz.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000);
    Calendar calendar = new GregorianCalendar(tz);

    int year = calendar.get(Calendar.YEAR);
    int month = calendar.get(Calendar.MONTH); // Jan = 0, dec = 11
    int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
    int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);

    int hour = calendar.get(Calendar.HOUR); // 12 hour clock
    int hourOfDay = calendar.get(Calendar.HOUR_OF_DAY); // 24 hour clock
    int minute = calendar.get(Calendar.MINUTE);
    int second = calendar.get(Calendar.SECOND);
    int millisecond = calendar.get(Calendar.MILLISECOND);

    int findHour = 12;
    int findMinutes = 5;

    /*
    calendar.add(Calendar.HOUR_OF_DAY, -1);
    int hourBefore = calendar.get(Calendar.HOUR_OF_DAY);
            
    calendar.add(Calendar.HOUR_OF_DAY, 2);
    int hourAfter = calendar.get(Calendar.HOUR_OF_DAY);
    */

    String posmonth = String.valueOf(month + 1);
    String posdayOfMonth = String.valueOf(dayOfMonth);
    String posdayOfWeek = String.valueOf(dayOfWeek);
    String posweekOfYear = String.valueOf(weekOfYear);
    String posweekOfMonth = String.valueOf(weekOfMonth);
    String poshourOfDay = String.valueOf(hourOfDay);
    String posminute = String.valueOf(minute);
    String possecond = String.valueOf(second);
    String posmillisecond = String.valueOf(millisecond);

    Calendar iteratorCalendar;
    String vSQL;
    String iteratorHour;
    String iteratorMinute;
    Statement stm;
    JSONObject jData;
    JSONObject jDataMinute;
    JSONArray jArray = new JSONArray();
    JSONArray jArrayMinute = new JSONArray();
    String posIteratorHour;
    String posIteratorMinute;

    /*
    Inicializa Lista de Agendas
    */
    gDatos.getLstShowAgendas().clear();
    gDatos.getLstActiveAgendas().clear();

    for (int i = -findHour; i <= findHour; i++) {
        iteratorCalendar = new GregorianCalendar(tz);
        iteratorCalendar.add(Calendar.HOUR_OF_DAY, i);
        iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY));
        posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1);

        vSQL = "select " + iteratorHour
                + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where "
                + "     ageEnable=1 " + "     and substr(month," + posmonth + ",1) = '1'"
                + "     and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + "     and substr(dayOfWeek,"
                + posdayOfWeek + ",1) = '1'" + "     and substr(weekOfYear," + posweekOfYear + ",1) = '1'"
                + "     and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + "     and substr(hourOfDay,"
                + posIteratorHour + ",1) = '1'";
        logger.debug("i: " + i + " vSQL: " + vSQL);
        try {
            stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);
            jData = new JSONObject();

            ResultSet rs = stm.executeQuery(vSQL);
            if (rs != null) {
                while (rs.next()) {
                    jData = new JSONObject();
                    jData.put("horaAgenda", rs.getString("horaAgenda"));
                    jData.put("ageID", rs.getString("ageID"));
                    jData.put("month", rs.getString("month"));
                    jData.put("dayOfMonth", rs.getString("dayOfMonth"));
                    jData.put("weekOfYear", rs.getString("weekOfYear"));
                    jData.put("weekOfMonth", rs.getString("weekOfMonth"));
                    jData.put("hourOfDay", rs.getString("hourOfDay"));
                    jArray.put(jData);
                    gDatos.getLstShowAgendas().add(jData);
                }
            } else {
                jData.put("horaAgenda", iteratorHour);
                jData.put("ageID", "");
                jData.put("month", "");
                jData.put("dayOfMonth", "");
                jData.put("weekOfYear", "");
                jData.put("weekOfMonth", "");
                jData.put("hourOfDay", "");
                jArray.put(jData);
                gDatos.getLstShowAgendas().add(jData);
                System.out.println("No hay registros");
            }
            stm.close();
        } catch (SQLException | JSONException e) {
            logger.error(e.getMessage());
        }
    }

    iteratorCalendar = new GregorianCalendar(tz);
    iteratorHour = String.valueOf(iteratorCalendar.get(Calendar.HOUR_OF_DAY));
    posIteratorHour = String.valueOf(Integer.valueOf(iteratorHour) + 1);

    for (int i = -findMinutes; i <= 0; i++) {
        iteratorCalendar = new GregorianCalendar(tz);
        iteratorCalendar.add(Calendar.MINUTE, i);
        iteratorMinute = String.valueOf(iteratorCalendar.get(Calendar.MINUTE));
        posIteratorMinute = String.valueOf(Integer.valueOf(iteratorMinute) + 1);

        vSQL = "select " + iteratorMinute
                + " horaAgenda,ageID, month, dayOfMonth, dayOfWeek, weekOfYear, weekOfMonth, hourOfDay from process.tb_agenda where "
                + "     ageEnable=1 " + "     and substr(month," + posmonth + ",1) = '1'"
                + "     and substr(dayOfMonth," + posdayOfMonth + ",1) = '1'" + "     and substr(dayOfWeek,"
                + posdayOfWeek + ",1) = '1'" + "     and substr(weekOfYear," + posweekOfYear + ",1) = '1'"
                + "     and substr(weekOfMonth," + posweekOfMonth + ",1) = '1'" + "     and substr(hourOfDay,"
                + posIteratorHour + ",1) = '1'" + "     and substr(minute," + posIteratorMinute + ",1) = '1'";
        logger.debug("i: " + i + " vSQL: " + vSQL);
        try {
            stm = gDatos.getServerStatus().getMetadataConnection().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                    ResultSet.CONCUR_READ_ONLY);

            ResultSet rs = stm.executeQuery(vSQL);
            if (rs != null) {
                while (rs.next()) {
                    jDataMinute = new JSONObject();
                    jDataMinute.put("horaAgenda", rs.getString("horaAgenda"));
                    jDataMinute.put("ageID", rs.getString("ageID"));
                    jDataMinute.put("month", rs.getString("month"));
                    jDataMinute.put("dayOfMonth", rs.getString("dayOfMonth"));
                    jDataMinute.put("weekOfYear", rs.getString("weekOfYear"));
                    jDataMinute.put("weekOfMonth", rs.getString("weekOfMonth"));
                    jDataMinute.put("hourOfDay", rs.getString("hourOfDay"));
                    jArrayMinute.put(jDataMinute);
                    gDatos.getLstActiveAgendas().add(jDataMinute);
                }
            }
            stm.close();
        } catch (SQLException | JSONException e) {
            logger.error(e.getMessage());
        }
    }

    for (int i = 0; i < gDatos.getLstShowAgendas().size(); i++) {
        logger.debug(gDatos.getLstShowAgendas().get(i).toString());
    }

    for (int i = 0; i < gDatos.getLstActiveAgendas().size(); i++) {
        logger.debug(gDatos.getLstActiveAgendas().get(i).toString());
    }

    logger.info("Finaliza busquenda agendas activas...");
}

From source file:edu.fullerton.framemonitor.ChangeListener.java

public ChangeListener(PrintStream log, BlockingQueue<File> outQue) {
    this.log = log;
    this.outQue = outQue;

    sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    SimpleTimeZone utctz = new SimpleTimeZone(0, "UTC");
    GregorianCalendar now = new GregorianCalendar(utctz);
    sdf.setTimeZone(utctz);/*from   ww  w  .j ava  2s . c  o m*/
    fnamePat = Pattern.compile("(.+)-(\\d+)-(\\d+)\\..*(gwf|tmp)");
}

From source file:com.emc.vipr.ribbon.ViPRDataServicesServerList.java

public ViPRDataServicesServerList() {
    rfc822DateFormat.setTimeZone(new SimpleTimeZone(0, "GMT"));
    try {//from w ww.j av a  2 s  .c  o m
        unmarshaller = JAXBContext.newInstance(ListDataNode.class).createUnmarshaller();
    } catch (JAXBException e) {
        throw new RuntimeException("can't create unmarshaller", e);
    }
    PoolingClientConnectionManager cm = new PoolingClientConnectionManager();
    cm.setDefaultMaxPerRoute(10);
    httpClient = new DefaultHttpClient(cm);
}

From source file:wsattacker.sso.openid.attacker.evaluation.attack.ReplayAttack.java

@Attack(number = 0)
private AttackResult performSameResponseNonceAttack() {
    OpenIdServerConfiguration.getAttackerInstance().setPerformAttack(true);

    String description = "The same timestamp and nonce in two consecutive " + "Authentication Responses.";

    // current time in utc
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
    dateFormat.setTimeZone(new SimpleTimeZone(SimpleTimeZone.UTC_TIME, "UTC"));
    String timestamp = dateFormat.format(new Date()) + RandomStringUtils.random(8, true, true);
    ;//www.j  a v a2 s  .c  o  m

    // set response_nonce
    AttackParameter responseNonceParameter = keeper.getParameter("openid.response_nonce");
    responseNonceParameter.setAttackValueUsedForSignatureComputation(true);
    responseNonceParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    responseNonceParameter.setAttackMethod(HttpMethod.GET);
    responseNonceParameter.setAttackValue(timestamp);

    // include modified response_nonce in signature
    AttackParameter sigParameter = keeper.getParameter("openid.sig");
    sigParameter.setValidMethod(HttpMethod.DO_NOT_SEND);
    sigParameter.setAttackMethod(HttpMethod.GET);

    // two logins
    LoginResult loginResult = serviceProvider.login(User.ATTACKER);
    LoginResult loginResult2 = serviceProvider.loginAndDetermineAuthenticatedUser(User.ATTACKER);

    boolean success = loginResult2.getAuthenticatedUser() == User.ATTACKER;
    Result result = success ? Result.SUCCESS : Result.FAILURE;
    Interpretation interpretation = success ? Interpretation.CRITICAL : Interpretation.PREVENTED;

    if (loginResult2.hasDirectVerification() && success) {
        result = Result.NOT_PERFORMABLE;
        interpretation = Interpretation.NEUTRAL;
    }

    assert isSignatureValid(loginResult2) : "Signature is not valid!";

    loginResult2.addLogEntriesAtStart(loginResult.getLogEntries());

    return new AttackResult(description, loginResult2, result, interpretation);
}