0
        <script type="text/javascript">
                @if (@Model.Invoice.InvoiceDate != null)
                {

                    <text>
                    function UTCToLocalTime(date) {
                        var time = new Date(Date.parse(date));
                        var timeOffset = -((new Date()).getTimezoneOffset() / 60);
                        time.setHours(d.getHours() + timeOffset);
                        return time;
                    }


                    var date = @Model.Invoice.InvoiceDate
                    UTCToLocalTime(date);
                    </text>




                }
                </script>

I am printing the above invoice and its open in a window. I am getting a Unexpected number error.

enter image description here

2 Answers 2

3

That sequence of numbers is not recognized by JavaScript. If you put it in quotes, it'll be treated like a string instead and be valid:

var date = '@Model.Invoice.InvoiceDate';

Or, if you want a date object (and have a valid date for it!):

var date = new Date('@Model.Invoice.InvoiceDate');
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use:

var date = '@Model.Invoice.InvoiceDate';

Since Date.parse is used to parse a string in javascript.

More info about Date.parse here.

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.