Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:42:10+00:00 2026-06-03T09:42:10+00:00

I Looking for a method that convert time string into Calendar look like this:

  • 0

I Looking for a method that convert time string into Calendar look like this:

   public static Calendar stringToCalendar(String strDate, TimeZone timezone){
    String FORMAT_DATETIME = "yyyy-MM-dd'T'HH:mm:ss";
    SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME);
    sdf.setTimeZone(timezone);
    Date date = sdf.parse(strDate);
    Calendar cal = Calendar.getInstance(timezone);
    cal.setTime(date);
    return cal;
   }

This code above does not work.
For example: when I pass time string ‘2012-05-08T09:10:10‘ with pattern yyyy-MM-dd’T’HH:mm:ss and Timezone is GMT+7, the result (from Calendar object) should be: 2012-05-08T16:10:10
The problem is for some reasons, I don’t want to use Joda time. So, how can I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:42:12+00:00Added an answer on June 3, 2026 at 9:42 am

    Simply use a SimpleDateFormat and set the TimeZone on it. Then invoke the parse() method.

    EDIT:


    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.TimeZone;
    
    public class temp2 {
    
        public static void main(String[] args) throws ParseException {
            String s = "2012-05-08T09:10:10";
            Calendar cal = stringToCalendar(s, TimeZone.getTimeZone("GMT+0"));
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            sdf.setTimeZone(TimeZone.getTimeZone("GMT+7"));
            System.err.println(sdf.format(cal.getTime()));
        }
    
        public static Calendar stringToCalendar(String strDate, TimeZone timezone) throws ParseException {
            String FORMAT_DATETIME = "yyyy-MM-dd'T'HH:mm:ss";
            SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_DATETIME);
            sdf.setTimeZone(timezone);
            Date date = sdf.parse(strDate);
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            return cal;
        }
    
    }
    

    outputs:

    2012-05-08 16:10:10
    Where the difference is indeed 7 hours

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What I'm looking for is a method that works like captureScreenshot(String path), but instead
I am looking for a class or method that takes a long string of
I am looking into catching every method that is defined on a base class,
I'm looking for a method of turning a NSMutableArray into a string. Is there
I am looking for method for parsing route path like this: ActionController::Routing.new(post_path).parse #=> {:controller
I'm looking to see if I can design a HtmlHelper extension method that will
I'm looking for an implementation of java.util.Map that has a method that will return
I'm looking for a method or an event that would get fired when a
I am looking for a method to monitor a running program that I have
I'm working with cocoa on the iPhone and I'm looking for some method like:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.