public static MvcHtmlString BrowserDisplay(
            this HtmlHelper htmlHelper,
            DateTime? dateTime,
            BrowserDateDisplay browserDateDisplay = DefaultBrowserDateDisplay)
        {
            long? msSinceUnixEpoch = null;
            if (dateTime.HasValue)
            {
                msSinceUnixEpoch = (long)((TimeSpan)(dateTime.Value.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))).TotalMilliseconds;
            }

            var momentFormat = BrowserDateDisplayConverter.ToMomentJsFormat(browserDateDisplay);

            return MvcHtmlString.Create(string.Format(
                @"<span data-aspnet-browser-locale=""{0}"" data-aspnet-browser-locale-momentjs-format=""{1}"">{2}</span>",
                msSinceUnixEpoch,
                momentFormat,
                dateTime.HasValue ? dateTime.Value.ToUniversalTime().ToString() + " UTC" : NullValueDisplay));
        }
        public static string ToMomentJsFormat(BrowserDateDisplay browserDateDisplay)
        {
            switch (browserDateDisplay)
            {
                case BrowserDateDisplay.DateTime:
                    return "lll";

                case BrowserDateDisplay.NumericDateTime:
                    return "l LT";

                case BrowserDateDisplay.DateOnly:
                    return "l";

                case BrowserDateDisplay.TimeOnly:
                    return "LT";

                default:
                    throw new ArgumentException("browserDateDisplay value is not supported.");
            }
        }
Beispiel #3
0
        public static string ToMomentJsFormat(BrowserDateDisplay browserDateDisplay)
        {
            switch (browserDateDisplay)
            {
            case BrowserDateDisplay.DateTime:
                return("lll");

            case BrowserDateDisplay.NumericDateTime:
                return("l LT");

            case BrowserDateDisplay.DateOnly:
                return("l");

            case BrowserDateDisplay.TimeOnly:
                return("LT");

            default:
                throw new ArgumentException("browserDateDisplay value is not supported.");
            }
        }
        public static MvcHtmlString BrowserDisplay(
            this HtmlHelper htmlHelper,
            DateTime?dateTime,
            BrowserDateDisplay browserDateDisplay = DefaultBrowserDateDisplay)
        {
            long?msSinceUnixEpoch = null;

            if (dateTime.HasValue)
            {
                msSinceUnixEpoch = (long)((TimeSpan)(dateTime.Value.ToUniversalTime() - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc))).TotalMilliseconds;
            }

            var momentFormat = BrowserDateDisplayConverter.ToMomentJsFormat(browserDateDisplay);

            return(MvcHtmlString.Create(string.Format(
                                            @"<span data-aspnet-browser-locale=""{0}"" data-aspnet-browser-locale-momentjs-format=""{1}"">{2}</span>",
                                            msSinceUnixEpoch,
                                            momentFormat,
                                            dateTime.HasValue ? dateTime.Value.ToUniversalTime().ToString() + " UTC" : NullValueDisplay)));
        }