0

I am using getTimezoneOffset() method of javascript and it's giving me the time difference between UTC time and local time, in minutes.For example, If user'stime zone is GMT+2, -120 will be returned.I am passing these minutes to my asp.net c# method:

  1. How to convert the UTC time saved in my SQL server table to local time according to the upper passing time difference in c# method?

Currently i am using following method to change utc time to user timezone time:

public IHttpActionResult GetProductions(int timeOffset, int quarter)
{
    int minutes = 0;
    if (timeOffset < 0)
    {
        minutes = Math.Abs(timeOffset);
    }
    else
    {
        minutes = timeOffset * -1;
    }
    var cullingDatasets = _reportingRepository.GetProductions().ToList().Select(d => new
    {
        DeliveryDate = d.Delivered.Value.AddMinutes(minutes)
    }).ToList();

    return Content(HttpStatusCode.OK, cullingDatasets, Configuration.Formatters.JsonFormatter);
}
  1. If I pass my c# method TimezoneOffset(time get by using getTimezoneOffset() in javascript) and a quarter of the year(like 1st,2nd,3rd, and 4th) then how can I get the array of first dates of all weeks in the given quarter like the following example?

Example: If I open the site from India then I pass from browser timedifferene=-330 and quarter=4 then I need the return from c# method is following array: [05/09,12/09,19/09,26/09,3/10,10/10,17/10,24/10,31/10,7/11,14/11,21/11,28/11,5/12,12/12,19/12,26/12]

Note: I need the first days of the quarter by user timezone by passing the time difference in UTC and local time.

Manjit
  • 221
  • 2
  • 4
  • 15
  • Have you tried anything? Stack Overflow isn't a code writing service. – Heretic Monkey Dec 30 '16 at 15:55
  • yes, i tried to convert UTC time to local by adding minutes l in UTC time like the above code.I don't know its correct way or not. and for getting the weeks the first day I am totally blank yet. – Manjit Dec 30 '16 at 16:02
  • You'll want to do some research. The [documentation for the DateTime](https://msdn.microsoft.com/en-us/library/system.datetime(v=vs.110).aspx) structure is pretty complete, and there are questions on SO about [getting the start of the week](http://stackoverflow.com/q/38039/215552). Look at the questions in the Related section to the right also. – Heretic Monkey Dec 30 '16 at 16:05
  • I researched on it and unable to find anything else.If I found something I will never waste your time.Kindly try to understand my situation.I am stuck on it. – Manjit Dec 30 '16 at 16:08
  • .NET's DateTimeOffset class supports offsets. It's not a method. Don't try to find JavaScript methods in .NET, or try to "fix" what isn't broken. DateTime itself offers methods for conversions between UTC and local time but DateTimeOffset allows you to specify the offset explicitly. – Panagiotis Kanavos Dec 30 '16 at 16:17

0 Answers0