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 4614634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:43:40+00:00 2026-05-22T01:43:40+00:00

I declared Calendar and SimpleDateFormat like this: calendar = Calendar.getInstance(TimeZone.getTimeZone(Malaysia)); final SimpleDateFormat sdf =

  • 0

I declared Calendar and SimpleDateFormat like this:

calendar = Calendar.getInstance(TimeZone.getTimeZone("Malaysia"));
final SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MMMMM.dd hh:mm aaa");

or:

calendar = Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00"));

Then I call this:

sdf.format(calendar.getTime());

but result is not in correct time zone (+8 hours). What could be the problem?

  • 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-05-22T01:43:40+00:00Added an answer on May 22, 2026 at 1:43 am

    Unless you are going to perform Date/Time related calculations, there is no point in instantiating Calendar with given TimeZone. After calling Calendar’s getTime() method, you will receive Date object, which is timezone-less either way (GMT based, actually).

    What you need to do, is to set TimeZone for formatter instead. And also do not bother with passing your own format, there is a built-in already:

        // get current time
        // you could just as well use Date now = new Date();
        Calendar now = Calendar.getInstance();
    
        // Locale for formatter
        Locale malaysianLocale = new Locale("ms", "MY");
        // Default date and time format for Malaysia
        DateFormat defaultMalaysianFormatter = DateFormat.getDateTimeInstance(
                DateFormat.DEFAULT, DateFormat.DEFAULT, malaysianLocale);
        // This step is crucial
        TimeZone malaysianTimeZone = TimeZone.getTimeZone("Asia/Kuala_Lumpur");
        defaultMalaysianFormatter.setTimeZone(malaysianTimeZone);
    
        System.out.println(defaultMalaysianFormatter.format(now.getTime()));
    

    This prints something like 10 Mei 2011 2:30:05 AM, which I believe is your desired result.

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

Sidebar

Related Questions

I have two classes declared like this: class Object1 { protected ulong guid; protected
I am actually using this calendar source code, but I did encountered a problem
I declared an array as shown below: int[] arr = new int[10]; Then I
I am creating a calendar table for my warehouse. I will use this as
I declared the dictionary obj. Dictionary<string, string> aDict = new Dictionary<string, string>(); aDict .Add(IP,
I declared a structure with the new game_struct. It has these contents : struct
I Declared: std::string input_file=1.txt; then I tried to do this command: static ifstream myfile
I declared vector<test*> test1; as a private, and I'd like to create getter and
I declared a private variable vector<SomeClass> theVector; someplace inside my SomeClass class. Why can't
I've declared Javascript arrays in such a way that I could then access them

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.