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

  • SEARCH
  • Home
  • 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 8154337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:18:43+00:00 2026-06-06T16:18:43+00:00

private void getSelectedTime(final String json){ Calendar now = Calendar.getInstance(); int year = now.get(Calendar.YEAR); int

  • 0
 private void getSelectedTime(final String json){

        Calendar now = Calendar.getInstance();
        int year = now.get(Calendar.YEAR);
        int month = now.get(Calendar.MONTH); // Note: zero based!
        int day = now.get(Calendar.DAY_OF_MONTH);
        int hour = now.get(Calendar.HOUR_OF_DAY);
        int minute = now.get(Calendar.MINUTE);
        int second = now.get(Calendar.SECOND);
        int millis = now.get(Calendar.MILLISECOND);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");


        JSONArray list;
        JSONObject jsonObject;

        try {
            jsonObject = new JSONObject(json);

            list = jsonObject.getJSONArray("3");
            StringTokenizer tokenizer = new StringTokenizer(list.get(0).toString(),"-");
            String startTime = tokenizer.nextToken();
            String endTime = tokenizer.nextToken();
            String temp1 = year+"/"+month+"/"+day+" "+startTime;
            String temp2 = year+"/"+month+"/"+day+" "+endTime;
            System.out.println("temp1="+temp1);
            System.out.println("temp2="+temp2);

            Date date1 = dateFormat.parse(temp1); // temp1=2012/5/25 03:00
            Date date2 = dateFormat.parse(temp2); //temp2=2012/5/25 03:06

            System.out.println("Year1="+date1.getYear());
            System.out.println("Month1="+date1.getMonth());
            System.out.println("Day1="+date1.getDay());
            System.out.println("Hour1="+date1.getHours());
            System.out.println("Minutes1="+date1.getMinutes());

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

    }

}

In my application I am working with time and I have some issue here. Take a look below I have this result.

list.get(0) = 03:00-03:06
temp1=2012/5/25 03:00
temp2=2012/5/25 03:06

But when I am trying do this

System.out.println("Year="+date1.getYear());
System.out.println("Month="+date1.getMonth());
System.out.println("Day="+date1.getDay());
System.out.println("Hour="+date1.getHours());
System.out.println("Minutes="+date1.getMinutes());

I’ve got this result

Year=112
Month=4
Day=5
Hour=3
Minutes=0

Could anyone tell me why the result is wrong?

  • 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-06T16:18:44+00:00Added an answer on June 6, 2026 at 4:18 pm

    Could anyone tell me why I the result is wrong?

    Sure – you’re using deprecated methods (you should be getting warnings – don’t ignore them!), and you haven’t read the docs for them. For example, from Date.getYear():

    Returns a value that is the result of subtracting 1900 from the year that contains or begins with the instant in time represented by this Date object, as interpreted in the local time zone.

    If you want to stick to the JDK, you should use java.util.Calendar instead (populating it with the Date via setTime) in an appropriate time zone. Note that months are still 0-based in Calendar, although the year is at least more sensible.

    However, it would generally be better to use Joda Time if you possibly can. It’s a much better thought-out API. It may be too large for you to want to use it on Android though – you may wish to see whether there’s a cut-down version available.

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

Sidebar

Related Questions

private void save(Rectangle src, Rectangle dest, string fName, int width, int height, Bitmap file)
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i <
private void CopyAssets2() { AssetManager assetManager = getAssets(); String[] files = null; try {
private void StringAction(string aString) // method to be called { return; } private void
private void gcw_PositionChanged(object sender, GeoPositionChangedEventArgs e) { // Stop the GeoCoordinateWatcher now that we
private void dateTimePicker1_ValueChanged(object sender, Series myseries, int multiplier, EventArgs e) { if (datelimitsset ==
private void btnMiles_Click(object sender, EventArgs e) { try { int milesless200 = int.Parse(txtMiles.Text); int
private void SaveAsPicture_Click(object sender, RoutedEventArgs e) { WriteableBitmap bmp = new WriteableBitmap(MyUIElement, null); var
private void setFPAlarm() { Intent intent = new Intent(this, FPService.class); PendingIntent pi = PendingIntent.getService(this,
private void EnsureCurrentlyValid() { //I'm valid if IDataErrorInfo.this[] returns null for every property var

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.