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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:00:36+00:00 2026-06-15T16:00:36+00:00

I am trying to write a REST-API with Jersey. From javascript I get a

  • 0

I am trying to write a REST-API with Jersey. From javascript I get a Datestring like:

Tue Oct 16 2012 07:10:55 GMT+0200 (CEST)

(That’s what

new Date().toString()

does, but this is not in my scope.)

This date string can be parsed by implementing an own @ContextResolver. I been googling for about a day and the best SimpleDateFormat I could put together is:

SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd yyyy HH:mm:ss 'GMT'z '('z')'", Locale.ROOT);

But as you can see the ‘GMT’-part and the brackets are “hard-coded”. Is there any better solution without changing the javascript part?

  • 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-15T16:00:37+00:00Added an answer on June 15, 2026 at 4:00 pm

    @kidmenot: Thanks for the link, but that solution requires to handle the javascript-date “manually” on the java side and to change the Javascript-side. So finally we needed to change the javascript-part only. There was

    var myDate = new Date():
    // ... many LOCs
    var myDateString = "" + myDate + "";
    

    scattered all over the js-code. So just changing that to

    var myDate = new Date():
    // ... many LOCs
    var myDateString = myDate;
    

    solved the issue, because later on the was a

    JSON.stringify()
    

    just before sending it to the server. That JSON.stringify() calls myDate.toJSON() which returns an ISO-8601 datestring which gets processed by Jersey without the need for any further coding.

    So we chose this solution to spare us from future complications.

    Edit half a year later:

    This parse problem occured often and was finally inevitable because of some js-framework.
    The following is our Java-Solution:

    public static Date jsDateStringToJavaDate(String jsDateString) throws ParseException{
    
        String[] arrStrDateParts = jsDateString.split(" ");
        SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd yyyy HH:mm:ss", Locale.ENGLISH);
        sdf.setTimeZone(TimeZone.getTimeZone(arrStrDateParts[5].substring(0,6)+":"+arrStrDateParts[5].substring(6)));
        return sdf.parse(arrStrDateParts[0]+" "+arrStrDateParts[1]+" "+arrStrDateParts[2]+" "+arrStrDateParts[3]+" "+arrStrDateParts[4]);       
    }
    

    If you got a better solution, please post it here. Thx

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

Sidebar

Related Questions

I'm trying to write a REST-API server with NodeJS like the one used by
I'm trying to write a REST API. I honestly do not know anything related
So I'm trying to write tests for my REST API (built on top of
Im trying to use the Twilio Rest API to get a list of call
I am trying to use the Jersey client API to consume a third-party REST
I wrote REST service using ASP.NET Web API. I'm trying to send HttpDelete request,
Trying to write a chat, like on facebook, I wondered if two clients can
I am trying to send an URL-encoded post to a REST API implemented in
I'm trying to write REST-behaviour into my ASP.NET MVC2 app, but I'm having a
I'm a newbie to WCF, REST etc. I'm trying to write a service and

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.