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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:25:51+00:00 2026-05-24T23:25:51+00:00

My code: import net.sf.json.JSONObject; import net.sf.json.JSONSerializer; … public void testDateSerializer() { final Date date

  • 0

My code:

import net.sf.json.JSONObject;
import net.sf.json.JSONSerializer;
...
public void testDateSerializer() {
  final Date date = new Date();
  log.info("Today's date: " + date + " and date.getTime()=" + date.getTime());
  final JSONObject jsonObjectForDate = (JSONObject) JSONSerializer.toJSON(date);
  log.info("Same date expressed in json: " + jsonObjectForDate.toString());
}

The output:

INFO - 2011-08-13 22:12:04,938 - TestJsonConversion.testDateSerializer(52) | Today's date: Sat Aug 13 22:12:04 EDT 2011 and date.getTime()=1313287924927
INFO - 2011-08-13 22:12:05,216 - TestJsonConversion.testDateSerializer(55) | Same date expressed in json: {"date":13,"day":6,"hours":22,"minutes":12,"month":7,"seconds":4,"time":1313287924927,"timezoneOffset":240,"year":111}

My questions:

  • Why year=111. We are still in 2011 unless I missed something!
  • I am on US ETD, so offset is -4 hours, not +240, which, even expressed in minutes is still wrong regarding the sign of the offset.

So what am I doing wrong? Is this a bug in the library? If so, what library should I use to accomplish the same conversion?

Thank you

  • 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-24T23:25:52+00:00Added an answer on May 24, 2026 at 11:25 pm

    Actually this behavior is completely expected, believe it or not.

    You are using the class java.util.Date. This class has mostly a bunch of deprecated methods. See the documentation here:

    http://download.oracle.com/javase/6/docs/api/java/util/Date.html

    Now your JSON serializer is just going to make a JSON string out of the getters in your Java object. Take a look at the getters in the java.util.Date class. Most are deprecated and you can see why. The year is relative to 1900! The time zone offset is in minutes backwards.

    To make your application work the way you would expect, check out the deprecation warnings for Date which tell you to use GregorianCalendar. However, I recommend using JodaTime. A little learning curve, but this is so worth it.

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

Sidebar

Related Questions

I have the following code: import java.net.InetAddress; public class lookup { public static void
I have the following code: import com.apple.dnssd.*; public interface IServiceAnnouncer { public void registerService();
The following is my Class code import java.net.*; import java.util.*; import java.sql.*; import org.apache.log4j.*;
This is my code: import datetime today = datetime.date.today() print(today) This prints: 2008-11-22 which
I have the following code: import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.ScrollPaneConstants; public
What's wrong with this code import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; /** * *
Here is my code realising the connection. import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import
Here is what I get: And here is my complete code: import java.net.*; import
I'm completely new to both VB.NET and JSON, and I'm trying to figure out
given the following code: import ctypes ip=192.168.1.1 thisdll = ctypes.cdll['aDLL'] thisdll.functionThatExpectsAnIP(ip) how can I

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.