Service returning incorrect date format

I am working with a webservice that returns dates in the format 1530158400000. However, I need to display them in the format "2018-06-12" on my AngularJS UI. The response object from the webservice includes a "protected Date trdDate" field, which is correctly formatted as "2018-06-12" when queried using Hibernate. Despite this, the date appears as 1530158400000 when displayed on the UI.

Answer №1

To achieve the desired date format, simply follow these steps:

  1. Create a new application.properties file or update your existing one with the following line:

    spring.jackson.serialization.write-dates-as-timestamps:false

  2. Add the

    @JsonFormat(pattern="yyyy-MM-dd")
    annotation to the date field in your DTO:

    @JsonFormat(pattern="yyyy-MM-dd")
    protected Date trdDate

Output: "2018-06-08T18:35:53.153+0000"

Remember, you can customize the pattern to fit your specific date format preferences.

Thank you!

Answer №2

When your input is in milliseconds representing a date, you can use the following code snippet:

var d = new Date(inputDate).toISOString().split('T')[0];

This code will give you the desired answer, with 'd' holding the formatted date.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The ActionListener code was executed multiple times

I created a JButton and added an ActionListener to it, but the code inside the public void actionPerformed(ActionEvent e) method is executing twice. Instead of printing "test" just once, it prints it twice. Here is the code snippet: JButton testbut = new ...

the display window is not visible

After implementing the following asp.net server code, my page is being redirected without displaying the print window: ScriptManager.RegisterStartupScript(this, typeof(Page), "printGrid", "javascript:window.print();", true); Page.Response.Redirect(Page. ...

The YouTube-Search NPM module is producing unexpected outcomes

I recently integrated the youtube-search NPM library with express to fetch the first youtube video based on a song name. app.get("/search", (req, res) => { var search = require("youtube-search"); var SONG = req.query.SONG; var opts = { maxR ...

How can I restrict Material UI TextFields with input type = file to only allow pdf files?

Is there a way to restrict users from uploading anything other than PDF files using input type=file? I've researched about using the accept attribute but seems like it's not compatible with material UI text fields. Is there an alternative soluti ...

Having trouble retrieving the text change value in AngularJS when editing a case

Here is the HTML code: <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7 ...

What's the best way to export a property name along with its data type, rather than having to specify it repet

Imagine having a setup like this: export type Style = Pick< React.CSSProperties, "margin" | "marginBottom" > where you can use it in a component like type Props = { style: Style } Instead of repeating the definition in ev ...

Add a new element dynamically and update its content on the fly

I am looking to clone certain elements and modify the text inside them using a regex. Here is my progress: (working fiddle - http://jsfiddle.net/8ohzayyt/25/) $(document).ready(function () { var divs = $('div'); var patt = /^\d&bso ...

Error Encountered: Unable to fulfill the request for textDocument/definition in

I am a fan of using VS Code for JavaScript and React (jsx) development. However, I sometimes encounter an issue where a panel pops up displaying the following message: [Error - 13:45:45] Request textDocument/definition failed. Message: Request textDocum ...

Managing the result efficiently when asp.net mvc ModelState IsValid is false

My colleagues and I are currently working on a CRUD application using .net mvc4. The project involves rendering dynamic content through jQuery based on customer choices. One challenge we face is the need to create multiple hidden inputs to pass additional ...

Looking to conceal an <hr> element using jQuery's slideToggle function and then reveal it when clicked once more

I recently embarked on my journey to learn jQuery. I encountered a challenge with a simple button that triggers the slideToggle function to show/hide a div. Directly above this toggled div, there is an break line which I want to hide when the button is in ...

Tips for formatting text preceding a specific symbol

When text is generated from a for loop, such as "Hello: how are you?" and "Hi: I am fine", the goal is to make the text preceding the colon bold. For instance, in the examples provided, "Hello" and "Hi" should appear ...

Utilize React's Context Provider to centrally manage all state while incorporating async calls

I am currently exploring more refined methods to establish a provider/consumer setup in which an asynchronous call is initiated from the provider, but the consumer does not need to handle state management. Within my context provider, I am fetching data to ...

Issues with AngularJS have arisen, as it is currently unable to recognize and access variables as needed

As a newcomer to web design and Angular, I am trying to replicate this example, where I consume a RESTful web service and use AngularJS to display the JSON data. However, I'm facing issues with my implementation. Here's how my main.jsp file look ...

What steps do I need to take to link my form with Ajax and successfully submit it?

Here is my HTML code: {% extends 'base.html' %} {% block content %} <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create a Recipe ...

A step-by-step guide on resolving the InputStream ReadTimeout issue during FileUpload

My current project: is an asp.net mvc web application featuring a basic email form with file upload functionality and a send button. The email sending function works correctly, however, the files attached to the emails are coming through as empty. Upon de ...

Using regular expressions to replace all special characters, excluding dots

$('#price').keyup(function(){ $('#price').val($('#price').val().replace(/[_\W]+/g, "-")); }) Experience it firsthand here: http://jsfiddle.net/2KRHh/6/. In the scenario above, special characters are eliminated. ...

Fill the dropdown menu with options from a collection and automatically adjust the list based on the user's selection in the meteor

As a newcomer to Meteor, I am facing an issue with populating a select box from a MongoDB collection. Despite my attempts, the solution I tried below did not work as expected: <template name="clist"> <div class="input-field"> <select> ...

Utilizing a generated class within a library: a step-by-step guide

It's not located within the actual library, but rather in a separate library that relies on an annotation processor. The project structure I have is roughly as follows: Annotation Processor -> Android Library module -> Android App module In ...

FancyBox refuses to "pop"

I have been struggling for 2 hours to get FancyBox to work, and I cannot figure out why it is not working. It seems like I am missing something because instead of the image popping up, it just takes me to a new page. For example: I have linked both the th ...

Determine if a specific identifier is already present using Javascript or Jquery

Is there a way to determine if an html tag with its specific id is present more than once in the code? This is my pseudocode for checking: if($('#myId').length > 1) { // It exists twice } ...