Example usage for java.util TimeZone getTimeZone

List of usage examples for java.util TimeZone getTimeZone

Introduction

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

Prototype

public static TimeZone getTimeZone(ZoneId zoneId) 

Source Link

Document

Gets the TimeZone for the given zoneId .

Usage

From source file:io.swagger.test.client.ApiClient.java

public ApiClient() {
    // Use ISO 8601 format for date and datetime.
    // See https://en.wikipedia.org/wiki/ISO_8601
    this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");

    // Use UTC as the default time zone.
    this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));

    // Set default User-Agent.
    setUserAgent("Java-Swagger");

    // Setup authentications (key: authentication name, value: authentication).
    authentications = new HashMap<String, Authentication>();
    authentications.put("api_key", new ApiKeyAuth("header", "api_key"));
    authentications.put("petstore_auth", new OAuth());
    // Prevent the authentications from being modified.
    authentications = Collections.unmodifiableMap(authentications);
}

From source file:com.relecotech.common.controller.AcceptParameterController.java

@RequestMapping(value = "/{name}", method = RequestMethod.GET)
//public String getMovie(@PathVariable String name, ModelMap model) {
public @ResponseBody ModelAndView getParameter(@PathVariable String name) throws ParserConfigurationException {
    //String param =name;
    try {//from   w  ww .  j a v  a 2  s  .c o m
        Map<String, String> valueMap = new HashMap<String, String>();
        String[] data = name.split("&");
        for (String str : data) {
            String[] mapPair = str.split("=");
            valueMap.put(mapPair[0], mapPair[1]);
        }
        String logoutUrl = "https://" + valueMap.get("URL") + ".com";
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        SAMLCredential credential = (SAMLCredential) authentication.getCredentials();
        TimeZone timeZone = TimeZone.getTimeZone(valueMap.get("timeZone").replace("*", "/"));

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd hh:mm a");
        dateFormat.setTimeZone(timeZone);

        Calendar calobj = Calendar.getInstance(timeZone);
        String SystemCurrentTime = dateFormat.format(calobj.getTime());
        Date SystemCurrentDateTime = dateFormat.parse(SystemCurrentTime);
        // Date SystemCurrentDateTime = calobj.getTime();

        //SFDC Meeting DATE/TIME 
        String sfdcMeetingTime = valueMap.get("d").replace("*", "/");
        System.out.println("sfdcMeetingTime=" + sfdcMeetingTime);
        Date sfdcMeetingDateTime = dateFormat.parse(sfdcMeetingTime);
        //TIME Before Meeting can satarted 
        Date sfdcMeetingBeforeDateTime = dateFormat
                .parse(AddSubtractTime.getSubtractedTime(sfdcMeetingTime, timeZone));
        //TIME after Meeting cannot be satarted 
        Date sfdcMeetingAfterDateTime = dateFormat
                .parse(AddSubtractTime.getAddedTime(sfdcMeetingTime, timeZone));

        System.out.println("SystemCurrentDateTime=" + SystemCurrentDateTime);
        System.out.println("sfdcMeetingDateTime=" + sfdcMeetingDateTime);
        System.out.println("sfdcMeetingAfterDateTime=" + sfdcMeetingAfterDateTime);
        System.out.println("sfdcMeetingBeforeDateTime=" + sfdcMeetingBeforeDateTime);
        if (SystemCurrentDateTime.after(sfdcMeetingBeforeDateTime)
                && SystemCurrentDateTime.before(sfdcMeetingAfterDateTime)) {
            APIGenerator aPIGenerator = new APIGenerator();
            System.out.println("converted id=" + SalesforceIDConverter.convertID(valueMap.get("code")));
            System.out.println((credential.getAttributeAsString("ContactId")));
            if (valueMap.get("code")
                    .matches(SalesforceIDConverter.convertID(credential.getAttributeAsString("ContactId")))) {

                System.out.println("valuemap=" + valueMap);

                System.out.println("logout url=" + logoutUrl);
                String create = "attendeePW=ap" + "&meetingID=" + valueMap.get("name") + "&moderatorPW=newuser"
                        + "&name=" + valueMap.get("name") + "&logoutURL=" + logoutUrl;
                System.out.println("create parameter=" + create);
                XmlParser.runAPI(aPIGenerator.createAPI("create", create));
                // String join = "fullName=" + valueMap.get("fullName") + "&meetingID=" + valueMap.get("meetingID") + "&password=newuser";
                String join = "fullName=" + credential.getAttributeAsString("username") + "&meetingID="
                        + valueMap.get("name") + "&password=newuser";
                System.out.println("joinparam=" + join);
                aPIGenerator.createAPI("join", join);
                return new ModelAndView("redirect:" + aPIGenerator.apiWithChecksum);

            } else {
                Map<String, String> responceMap = XmlParser.runAPI(
                        aPIGenerator.createAPI("isMeetingRunning", "meetingID=" + valueMap.get("name")));
                String join = "fullName=" + credential.getAttributeAsString("username") + "&meetingID="
                        + valueMap.get("name") + "&password=ap";
                if (responceMap.get("running").matches("true")) {

                    aPIGenerator.createAPI("join", join);
                    return new ModelAndView("redirect:" + aPIGenerator.apiWithChecksum);
                } else {
                    String student = "<center>  <h1>Wait! Presenter has not joined meeting yet!</h1>\n"
                            //                                +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> "
                            + "     <h2>\n" + "           Please try after few minutes.\n" + "        \n"
                            + "<br>Meeting Date/Time:" + dateFormat.format(sfdcMeetingDateTime) + "<br><a href="
                            + logoutUrl + ">Back</a>" + "    </h2></center> ";
                    // return new ModelAndView("redirect:" + "/student.jsp");
                    return new ModelAndView("student", "student", student);
                }
            }

        } else {
            //                
            if (SystemCurrentDateTime.compareTo(sfdcMeetingDateTime) == -1) {

                String wait = "<center> <h1>Too Early for Meeting!</h1><br></center>\n"
                        //                             +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> "
                        + "  <center>  <h2>Meeting is not yet open.<br>\n"
                        + "  Please check meeting schedule time. \n<br>" + "<br>Meeting Date/Time:"
                        + dateFormat.format(sfdcMeetingDateTime) + "</h2><h3>System Current Date/Time:"
                        + dateFormat.format(SystemCurrentDateTime)
                        + "<br>*Meeting will open 15 minutes before scheduled time</h3><a href=" + logoutUrl
                        + ">Back</a>" + "  </center> ";
                return new ModelAndView("wait", "wait", wait);
            }
            //for Past Date
            if (SystemCurrentDateTime.compareTo(sfdcMeetingDateTime) == 1) {
                String wait = "<center> <h1>Meeting is Over!</h1><br></center>\n"
                        //                             +"<img src=\"${pageContext.request.contextPath}/images/bbbtime.jpg\" style=\"width:304px;height:228px\"/> "
                        + "  <center>  <h2>Meeting can not open.<br>\n"
                        + "        Meeting was scheduled on - \n<br>" + "<br>Meeting Date/Time:"
                        + dateFormat.format(sfdcMeetingDateTime) + "</h2><h3><br>System Current Date/Time:"
                        + dateFormat.format(SystemCurrentDateTime) + "<br><a href=" + logoutUrl + ">Back</a>"
                        + "  </h3>  </center> ";
                return new ModelAndView("wait", "wait", wait);

            }
            //                
        }

    } catch (Exception ex) {
        System.out.println("Exception=" + ex);
    }

    return null;
}

From source file:com.mercandalli.android.apps.files.common.dialog.DialogCreateArticle.java

public DialogCreateArticle(final Activity activity, final IListener listener) {
    super(activity);
    this.mActivity = activity;

    this.setContentView(R.layout.dialog_create_article);
    this.setTitle("Create Article");
    this.setCancelable(true);

    this.article_title_1 = (EditText) this.findViewById(R.id.title);
    this.article_content_1 = (EditText) this.findViewById(R.id.content);

    this.findViewById(R.id.request).setOnClickListener(new View.OnClickListener() {
        @Override/*from  w  w w  . j  a v a2s .c  o m*/
        public void onClick(View v) {

            SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
            dateFormatGmt.setTimeZone(TimeZone.getTimeZone("UTC"));

            String nowAsISO = dateFormatGmt.format(new Date());

            JSONObject json = new JSONObject();
            try {
                json.put("type", "article");
                json.put("date_creation", nowAsISO);
                json.put("article_title_1", article_title_1.getText().toString());
                json.put("article_content_1", article_content_1.getText().toString());

                SimpleDateFormat dateFormatGmtTZ = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm'Z'", Locale.US);
                dateFormatGmtTZ.setTimeZone(TimeZone.getTimeZone("UTC"));
                nowAsISO = dateFormatGmtTZ.format(new Date());

                List<StringPair> parameters = new ArrayList<>();
                parameters.add(new StringPair("content", json.toString()));
                parameters.add(new StringPair("name", "ARTICLE_" + nowAsISO));
                new TaskPost(mActivity, Constants.URL_DOMAIN + Config.ROUTE_FILE, new IPostExecuteListener() {
                    @Override
                    public void onPostExecute(JSONObject json, String body) {
                        if (listener != null) {
                            listener.execute();
                        }
                    }
                }, parameters, "text/html; charset=utf-8").execute();
            } catch (JSONException e) {
                Log.e(TAG, "DialogCreateArticle: failed to convert Json", e);
            }

            DialogCreateArticle.this.dismiss();
        }
    });

    DialogCreateArticle.this.show();
}

From source file:net.solarnetwork.node.test.AbstractNodeTransactionalTest.java

/**
 * Setup the {@link #dateTimeFormat} timezone.
 */
@BeforeTransaction
public void setupDateTime() {
    dateTimeFormat.setTimeZone(TimeZone.getTimeZone(TEST_TZ));
}

From source file:com.boozallen.cognition.ingest.storm.bolt.enrich.SetDateBoltTest.java

@Test
public void testEnrichGnip(@Mocked final LogRecord record) throws Exception {
    final Calendar calendar = Calendar.getInstance();
    calendar.clear();//w  w  w .j  a  v  a2s  .co m
    calendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    calendar.set(2015, Calendar.JULY, 12, 0, 0, 52);

    bolt.dateFields = Arrays.asList("postedTime");
    bolt.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSX";

    new Expectations() {
        {
            record.getValue(bolt.dateFields.get(0));
            result = "2015-07-12T00:00:52.000Z";
            record.setDate(calendar.getTime());
        }
    };
    bolt.process(record);
}

From source file:com.mycompany.craftdemo.utility.java

public static boolean isValidTime() {
    Calendar calendar = Calendar.getInstance();
    TimeZone fromTimeZone = calendar.getTimeZone();
    TimeZone toTimeZone = TimeZone.getTimeZone("EST");

    calendar.setTimeZone(fromTimeZone);/*from  www  .j av a 2 s. c  om*/
    calendar.add(Calendar.MILLISECOND, fromTimeZone.getRawOffset() * -1);
    if (fromTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, calendar.getTimeZone().getDSTSavings() * -1);
    }

    calendar.add(Calendar.MILLISECOND, toTimeZone.getRawOffset());
    if (toTimeZone.inDaylightTime(calendar.getTime())) {
        calendar.add(Calendar.MILLISECOND, toTimeZone.getDSTSavings());
    }

    int hour = calendar.get(Calendar.HOUR_OF_DAY);

    return hour >= 9 && hour <= 16;
}

From source file:at.rocworks.oa4j.logger.dbs.NoSQLJDBC.java

public NoSQLJDBC(NoSQLSettings settings, String driver, String url, String username, String password,
        String archive) {/*  w w w.j  a  v a  2s  . c o  m*/
    super(settings);
    this.driver = driver;
    this.url = url;

    this.username = username;
    this.password = password;
    this.archive = archive;

    this.cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));

    // default insert
    this.sqlInsertStmt = "INSERT INTO " + archive + "HISTORY "
            + "(tag, ts, value_number, value_string, value_timestamp, status, manager, user_)"
            + "VALUES (?,?,?,?,?,?,?,?)";

    // default select
    this.sqlSelectStmt = "SELECT %s FROM " + archive + "HISTORY " + " WHERE tag=? AND ts>=? AND ts<=?";

    try {
        Class.forName(driver);
        dataSourceWrite = new BasicDataSource();
        initStorage(dataSourceWrite, this.settings.getThreads());
        dataSourceQuery = new BasicDataSource();
        initStorage(dataSourceQuery, this.settings.getThreads() * this.settings.getThreads());
    } catch (ClassNotFoundException ex) {
        JDebug.StackTrace(Level.SEVERE, ex);
    }
}

From source file:gr.cti.android.experimentation.controller.BaseController.java

@PostConstruct
public void init() {
    final TimeZone tz = TimeZone.getTimeZone("UTC");
    dfTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");
    dfDay = new SimpleDateFormat("yyyy-MM-dd");
    dfTime.setTimeZone(tz);//from  ww w. ja va 2s  . co m
    dfDay.setTimeZone(tz);

}

From source file:com.capgemini.parking.places.ParkingGroupFactory.java

private Long getTimeStampFrom(String timestamp) {
    Long time = 1L;//from   www  .java2  s  . c  o  m
    try {
        SimpleDateFormat date = new SimpleDateFormat(configuration.getDate());
        date.setTimeZone(TimeZone.getTimeZone(configuration.getTimezone()));
        return date.parse(timestamp).getTime();
    } catch (ParseException ex) {
        ex.printStackTrace();
    }
    return time;
}

From source file:hudson.plugins.timestamper.TimestampNoteTest.java

/**
 * @throws Exception//  w w  w  .  ja va2s  .  co m
 */
@Before
public void setUp() throws Exception {
    systemDefaultTimeZone = TimeZone.getDefault();
    // Set the time zone to get consistent results.
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    setSystemTimeFormat(FORMAT);
}