Convert WebApi's Returned DateTime into Javascript's Date

web api
difference between web api and core web api
convert mvc controller to web api
httpactioncontext .net core
microsoft.aspnet.webapi.core .net core
ihttpactionresult .net core
how to add system.web reference in .net core
web api return types

I have a backend service written in WebApi and front end with AngularJS. From backend I have returned DateTime as below

public async Task<DateTime> GetDateTime(Guid id)
    DateTime dateTime = GetDateTime();
    return dateTime;

Inside angular controller I have received response like this

    id: $
function(data) {
    $scope.minSelectedScheduleDate = new Date(data);
    $scope.isBusy = false;
function(response) {
    $scope.isBusy = false;

But minSelectedScheduleDate become invalid date.

When I tried to see the data into console I saw something like this:

Resource {
    0: "2",
    1: "0",
    2: "1",
    3: "6",
    4: "-",
    5: "1",
    6: "0",
    7: "-",
    8: "2",
    9: "8",
    10: "T",
    11: "1",
    12: "1",
    13: ":",
    14: "3",
    15: "0",
    16: ":",
    17: "0",
    18: "0"

My question is, how can I receive a valid Date in Angular Controller?

You should be getting back a date as a string in ISO8601 format from your web api. To convert a string to a date you need to call the parse method on date.

$scope.minSelectedScheduleDate = Date.parse(data);

Migrating from ASP.NET Web API, In this article, we demonstrate the steps required to migrate a Web API implementation from ASP.NET Web API to ASP.NET Core MVC. Sections:: Review ASP. Create the destination project. From the File menu, select New > Project . Select the Blank Solution template and select Next . Name the solution WebAPIMigration . Select Create . Add the existing ProductsApp project to the solution.

I think you get date as response in object format of string, so try this

function(data) {
    var dateString="";
    for(var prop in data)
    $scope.minSelectedScheduleDate=new Date(dateString);

convert WebApi response from c# object to JSON, Yes i have it. The key was to keep it simple. Many thanks to Scott. Now my method works fine and provides the data in the Json format which i wanted! Here the  Download Web API starter app. Register OData. Add the Microsoft.AspNetCore.OData NuGet package to the project. Update the ConfigureServices method in Startup.cs with the following highlighted code:

The problem is I am returning DateTime object directly. If I return an anonymous object from my controller, then Javascript deserialize everything fine. Here is my current controller:

public async Task<DateTime> GetDateTime(Guid id)
    DateTime dateTime = GetDateTime();
    return new
        ScheduleDate = dateTime

Can I convert ASP.NET web Application into a web API?, Dear Sir, I have created a web application using c# language. Now I want to convert that project into a Web API as per the client  What I'm a bit confused on is whether I need to convert my existing Web API project in Visual Studio into a new console application, or if there's a way to create another console application Project in the solution which can act as the web server for the Web API services, or rather if there's a way to add a console element with a Main() entry

We have an Angular application that returns a revisionDate: Date property from a WebApi service. The first thing we do to it after it loads to convert it to a javascript Date like so:

// convert WebApi date format to javascript format
myJsonObject.revisionDate = new Date(myJsonObject.revisionDate.toString());

create Web API response, Learn about the return types of action methods which in turn will be embeded in to Web API response back to the client. Migrating from ASP.NET Web API to MVC 6 – exploring Web API Compatibility Shim Migrating an MVC 5 project to ASP.NET 5 and MVC 6 is a big challenge given that both of the latter are complete rewrites of their predecessors.

Converting MVC project to the Web API, Can we convert the MVC project to WebAPI or adding additional functionality of Restful Web API. This article describes the JSON and XML formatters in ASP.NET Web API. In ASP.NET Web API, a media-type formatter is an object that can: Read CLR objects from an HTTP message body; Write CLR objects into an HTTP message body; Web API provides media-type formatters for both JSON and XML. The framework inserts these formatters into the pipeline

Porting ASP.NET Web API apps to ASP.NET Core 2.0 – AC's Notes, NET Core The MVC web application framework and Web API framework are NET Core is to convert the old project to new project, and make  Create a project from ASP.NET SOAP To RESTful Converter template (You can find it on the left menu under Visual C# -> Web). Creating project through online templates. Start Microsoft Visual Studio. Select File -> New -> Project. Select online from the left menu. Search for ASP.NET SOAP To RESTful Converter. Choose project name and click OK.

Goodbye Web API: Your Guide to ASP.NET Core Web API, Migrate Existing Web API Controllers by Using a Compatibility Shim. The base class for Web API was ApiController, which no longer exists in  Open a command prompt and create a new directory for your application. Make that the current directory. Enter the following command in a console window: .NET Core CLI. dotnet new console --name WebApiClient. This creates the starter files for a basic "Hello World" application. The project name is "WebApiClient".

  • Sorry, this is not working. It says $scope.minSelectedScheduleDate is NaN
  • @EmdadulSawon - are you awaiting all tasks inside of your GetDateTime action? Can you share the angular service code for service.getDateTime?