Showing posts with label Current local time in UTC. Show all posts
Showing posts with label Current local time in UTC. Show all posts

Friday, February 13, 2015

Current local time in UTC

   
        try {
            Calendar calendar = Calendar.getInstance();
            int month = calendar.getTime().getMonth() + 1;
            String timeStampToMatch = calendar.getTime().getDate() + "-"
                    + month + "-" + calendar.get(Calendar.YEAR) + " "
                    + "01:01 pm";

            Log.i("======>", timeStampToMatch);

            DateFormat dateFormat = new SimpleDateFormat("d-M-yyyy H:m");

            Date date = dateFormat.parse(timeStampToMatch);
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            Log.i("======>", dateFormat.format(date));

        } catch (ParseException e) {
            e.printStackTrace();
        }