Here I am trying to convert a date to UTC and then converting same UTC date as new date. But the issue is that I am not getting same date which I passed.
All Date objects use a single UTC time value, so they are all inherently UTC and there is no need to "convert" them to UTC.
var myDate = '11/2/2015';
var myDateObj = new Date(myDate);
console.log('my Date is \n' + myDateObj);
You shouldn't use the Date constructor (or Date.parse) to parse strings, write a small function or use a library (e.g. moment.js, fecha.js).
The following (replacing getDay with getDate):
var tempDate = Date.UTC(myDateObj.getFullYear(),
myDateObj.getMonth(),
myDateObj.getDate());
is just a lengthy way of copying a date. Far simpler to use:
var tempDate = new Date(myDateObj);
If you want to get UTC date values, use UTC methods such as myDateObj.getUTCHours, myDateObj.getUTCMinutes, etc.
If you want to get the UTC date and time, use toISOString which returns values with offset 0000:
// Create a Date for 2 November, 2016
var date = new Date(2016,10,2);
// Copy it
var dateCopy = new Date(date);
// Show local date and time
console.log('Local date and time:\n' + dateCopy.toString());
// Show UTC date and time
console.log('UTC date and time :\n' + dateCopy.toISOString());
// Show UTC Date only
console.log('UTC date only :\n' + dateCopy.toISOString().substr(0,10));