1

In the AngularJS documentation, an example was shown:

<span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
    <span>{{1288323623006 | date:'medium'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
   <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
   <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
   <span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span><br>

What are the values on the left of the filter (1288323623006)? How to convert C# DateTime to it?

2 Answers 2

3

The number of milliseconds between midnight, January 1, 1970, and the specific date and time. In javascript you can get current time value using Date.now function

var currentTime = Date.now();

Angularjs date format can work with both time representation and Date object. So you don't need to convert DateTime to number on the server side, just use DateTime and convert it to Date object on client side.

See fiddle

If you really need number on the server side you can use code below

public static class DateTimeJavaScriptExtensions
{
   private static readonly long DatetimeMinTimeTicks =
      (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).Ticks;

   public static long ToJavaScriptMilliseconds(this DateTime dt)
   {
      return (long)((dt.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000);
   }
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can also add the filter at angular side so that it will convert into date format

app.filter("dateFilter", function () {
    return function (item) {
        if (item !== null) {
            return new Date(parseInt(item.substr(6)));
        }
        return "";
    };
});

And html side you have right like this

<td data-title="'Booking Date'" sortable="'Booking Date'" filter="{ 'booking_date': 'text' }">{{Booking.booking_date|dateFilter | date:"dd-MM-yyyy" }}</td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.