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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:37:26+00:00 2026-05-27T08:37:26+00:00

I am converting hex-string into a dateformat… I am getting wrong date time with

  • 0

I am converting hex-string into a dateformat… I am getting wrong date time with the following.. not sure where I am making a mistake.

    String s1="07:db:0c:08:16:0d:1e:00";    //2011-12-8,22:13:30.0
    s1 = s1.replaceAll(":", "");
    String year = s1.substring(0, 4);
    String month = s1.substring(4, 6);
    String day = s1.substring(6, 8);
    String hour = s1.substring(8, 10);
    String minute = s1.substring(10, 12);
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, Integer.parseInt(year, 16));
    cal.set(Calendar.MONTH, Integer.parseInt(month, 16));
    cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(day, 16));
    cal.set(Calendar.HOUR, Integer.parseInt(hour, 16));
    cal.set(Calendar.MINUTE, Integer.parseInt(minute, 16));
   System.out.println(cal.getTime());

my output is ‘Mon Jan 09 10:13:49 CST 2012’.. which is not correct (it should be 2011-12-8,22:13:30.0 — format ignored for now).

  • 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-27T08:37:26+00:00Added an answer on May 27, 2026 at 8:37 am

    Month in Java is represented by integer literals 0..11, that is January is 0, …, and December is 11. In this code, Integer.parseInt(month, 16) returns 12, which the Calendar object shifts to January next year (by increasing year).

    -EDIT-
    Also, set HOUR_OF_DAY instead of HOUR in cal.set(Calendar.HOUR, Integer.parseInt(hour, 16));

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

Sidebar

Related Questions

Possible Duplicate: Converting an uint64 into a (full)hex string, C++ I am trying to
In Python 2, converting the hexadecimal form of a string into the corresponding unicode
I'm taking a hex color value received as a string and converting it to
I have a hex string,st=9e. I need to convert it into byte and insert
I need to convert an int to hex string. When converting 1400 => 578
I am working on a project that involves converting data into dos date and
I'm getting a hex string that needs to be converted to a signed 8-bit
Any hints on parsing / converting / operating on hex values in c# ?
Converting to ODB.NET from System.Data.OracleClient and need help converting my connection string. Here is
I'm converting an application to use Java 1.5 and have found the following method:

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.