1. Paul Stovell
  2. Presentations

Source

Presentations / ASP.NET MVC / Samples / Controller Factories / Controllers / HomeController.cs

using System.Linq;
using System.Web.Mvc;
using System;

namespace Sample.Controllers
{
    public partial class HomeController : Controller
    {
        public ActionResult Index(string timeZone)
        {
            var allTimeZones = TimeZoneInfo.GetSystemTimeZones();
            var selectedTimeZone = allTimeZones.First(x => x.Id == timeZone);
            var offset = selectedTimeZone.GetUtcOffset(DateTime.UtcNow);
            var selectedTime = DateTime.UtcNow.Add(offset);
            
            ViewData.Model = new IndexModel(selectedTime, selectedTimeZone, allTimeZones);
            return View("Index");
        }
    }
}