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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:46+00:00 2026-05-23T15:20:46+00:00

I have a JSON object being returned to my app that contains a date

  • 0

I have a JSON object being returned to my app that contains a date

date": {
"year": 2011,
"month": 5,
"dayOfMonth": 30,
"hourOfDay": 16,
"minute": 13,
"second": 47
},

I need to use this date and store it in a SQL database, most likely as a string, so I parse this date object using the JSON functions in Java

Here I am trying to format the whole section as a string with dashes between the date and colons between the hours minutes seconds. Hoping that I could parse it with SimpleDateFormat, but that fails with parserexceptionerror

dataObj.getJSONObject("dateObject").getString("year") + "-" +
dataObj.getJSONObject("dateObject").getString("month") + "-" +
dataObj.getJSONObject("dateObject").getString("dayOfMonth") + " " +
dataObj.getJSONObject("dateObject").getString("hourOfDay") + ":" +
dataObj.getJSONObject("dateObject").getString("minute") + ":" +
dataObj.getJSONObject("dateObject").getString("second");

What would be the best way to go about this?

I need to take the JSON strings and combine them into a readable date which ideally I can turn into a string. This can be a formatted date – such as something simpledateformat will do, or it can be in milliseconds.

Insight Appreciated

  • 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-23T15:20:46+00:00Added an answer on May 23, 2026 at 3:20 pm

    Assuming that the goal is to transform a String representation of date information, formatted for example as “2011-5-30 16:13:47”, into a java.util.Date instance…

    String dateString = "2011-5-30 16:13:47";
    Date date = new SimpleDateFormat("yyyy-M-dd HH:mm:ss").parse(dateString);
    System.out.println(date);
    // output: Mon May 30 16:13:47 MST 2011
    
    String dateString2 = "2011-11-3 16:13:47";
    Date date2 = new SimpleDateFormat("yyyy-M-dd HH:mm:ss").parse(dateString2);
    System.out.println(date2);
    // output: Thu Nov 03 16:13:47 MST 2011
    

    An alternative would be to turn all of the JSON input values into Java ints, and then use Calendar.getInstance().set(year + 1900, month, date, hrs, min, sec).getTime().

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

Sidebar

Related Questions

I have the following JSON object being returned from my webserver. I can't figure
I have a string that contains a JSON object. Problem is the object is
I have a json object collection of geo locations that I build in the
Hi I have a JSON object that is a 2-dimentional array and I need
I have a request that returns a JSON object with a single property which
I have an AJAX application that downloads a JSON object and uses the data
I have a controller method that returns a jSON object and in one calling
I have JSON Object that looks something like the below object, this object can
I have an Action Method that returns a JSON-serialized object. The problem I'm having
I have a object that im serializing to a JSON object using JSON.Net. This

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.