Category Archives: ASP.NET

google maps in a razor view

These days I was working on a ASP.NET MVC web application to show events on a map. I had to use Google Maps for that purpose. I looked around for a way to integrate these maps. Fortunately Google provides a JavaScript API, which was the best option for me to explore. Although you can use it without any key, but creating and using a key is a good practice. If you have one, Google provides you usage statistics, and can warn you on exceeding your limits. For creating a key you will have to launch Google API Console. After going through the initial reference documents, I was ready to try it in my own application.

Continue reading

what JavaScript date gives you?

In my previous post I was trying to format date, and I noticed that I was not getting it correctly. Why was that, I assembled a small script to test all accessor methods provided by Date. Here is that code.

var today = new Date();
var message = "All accessor methods of date \n\n\n" +
    "getDate(): " + today.getDate() + "\n" +
    "getDay(): " + today.getDay() + "\n" +
    "getFullYear(): " + today.getFullYear() + "\n" +
    "getHours(): " + today.getHours() + "\n" +
    "getMilliseconds(): " + today.getMilliseconds() + "\n" +
    "getMinutes(): " + today.getMinutes() + "\n" +
    "getMonth(): " + today.getMonth() + "\n" +
    "getSeconds(): " + today.getSeconds() + "\n" +
    "getTime(): " + today.getTime() + "\n" +
    "getTimezoneOffset(): " + today.getTimezoneOffset() + "\n" +
    "getUTCDate(): " + today.getUTCDate() + "\n" +
    "getUTCDay(): " + today.getUTCDay() + "\n" +
    "getUTCFullYear(): " + today.getUTCFullYear() + "\n" +
    "getUTCHours(): " + today.getUTCHours() + "\n" +
    "getUTCMilliseconds(): " + today.getUTCMilliseconds() + "\n" +
    "getUTCMinutes(): " + today.getUTCMinutes() + "\n" +
    "getUTCMonth(): " + today.getUTCMonth() + "\n" +
    "getUTCSeconds(): " + today.getUTCSeconds() + "\n" +
    "getYear(): " + today.getYear() + "\n" +
    "toDateString(): " + today.toDateString() + "\n" +
    "toGMTString(): " + today.toGMTString() + "\n" +
    "toLocaleDateString(): " + today.toLocaleDateString() + "\n" +
    "toLocaleString(): " + today.toLocaleString() + "\n" +
    "toString(): " + today.toString() + "\n" +
    "toTimeString(): " + today.toTimeString() + "\n" +
    "toUTCString(): " + today.toUTCString();
alert(message);

Continue reading

formatting dates using JavaScript

Today I was working on a task which involved manipulating dates on client-side using JavaScript. Initially I found myself quite dumb, and did not had a clue how to do it.

Then I started experimenting, which is how I learn small things. unusual results:

  • string is not a date
  • conversion to date is not easy on my format (mm/dd/yyyy)
  • formatting a date on a particular format is not easy too

So looked around, I found Datejs, which I did not wanted to use, as my task was not so much complex. Then I found some other good resources, who helped me complete this tasks.

Continue reading