locked
Converting UTC back to Local Time w/ custom .dlls RRS feed

  • Question

  • Hi guys,


    I'm using this guys custom dlls that I bought (think telerik controls basically) to build my own silverlight calendar. Below is the code behind for one of the calendar's, now I have it saving to my SQL database in UTC, just having trouble with the retrieval, having the client onload convert the UTC (time in the db) to the local timezone. Just kinda stuck here.

        public partial class Personal : UserControl
    {
    public Personal()
    {
    InitializeComponent();

    scheduler.EditorManager = new EditorManager();
    scheduler.EditorManager.RegisterEditor(typeof(Appointment), typeof(SubClassedEditor));
    scheduler.EventManager.AppointmentSaving += new EventHandler<AppointmentSavingArgs>(EventManager_AppointmentSaving);

    //scheduler.EventManager.AppointmentsLoaded += new AppointmentsLoadedHandler(EventManager_AppointmentsLoaded);

    scheduler.HideNonWorkHours = true;

    LoadedData();

    }

    void EventManager_AppointmentsLoaded(object sender, EventArgs e)
            {
                throw new NotImplementedException();
            }


    void EventManager_AppointmentSaving(object sender, AppointmentSavingArgs e)
    {
    DateTime StartTime = e.Appointment.Start;
    DateTime FinishTime = e.Appointment.Finish;

    e.Appointment.Start = StartTime.ToUniversalTime();

    e.Appointment.Finish = FinishTime.ToUniversalTime();
    }


    private void LoadedData()
    {
    var ds = new DomainService1();

    var mapperAppointment = new DataMapper(typeof(personcal));

    scheduler.AppointmentDataAdapter = new RiaDataAdapter(ds, ds.personcals, "GetPersoncalsQuery", mapperAppointment);

    scheduler.AppointmentDataAdapter.LoadData();

    }

    // Executes when the user navigates to this page.


    }

    Free Trial of this guys SilverScheduler (what I using) is here: http://componentgizmos.com/Downloads.aspx

    Thanks for any help.


    Wednesday, August 4, 2010 9:57 AM

Answers

All replies

  • Hi

    If I understand right you are retrieving a datetime in UTC format from your database and wish to convert it to the local timezone? If so, I think this link will help:

     

    http://msdn.microsoft.com/en-us/library/bb397769.aspx

     

    Hope this helps.

    Wednesday, August 4, 2010 10:11 AM
  • That link did help, now trying to see where to do the conversion, in the LoadedData(); or AppointmentsLoaded() ... or neither?

    Still alittle new with Silverlight.

    Wednesday, August 4, 2010 11:37 AM
  • Ok I found the event I need to fire in order to get to my data, just need a little help with setting the value for the conversion.


     public void LoadedData()
            {
                var ds = new DomainService1();
    
                var mapperAppointment = new DataMapper(typeof(personalcalendar));
    
                scheduler.AppointmentDataAdapter = new RiaDataAdapter(ds, ds.personalcalendars, "GetPersonalcalendarsQuery", mapperAppointment);
    
                mapperAppointment.GettingMappedValue += new EventHandler<MappedValueEventArgs>(mapperAppointment_GettingMappedValue);
    
                scheduler.AppointmentDataAdapter.LoadData();
    
           }
    
            void mapperAppointment_GettingMappedValue(object sender, MappedValueEventArgs e)
            {
                e.PropertyName = "Start";
    
                e.Value = "";
    
                e.Handled = true;
            }


    Thursday, August 5, 2010 1:34 PM
  • Hi,

       I remember DateTime in Silverilght supports convert to local defaultly

       DateTimeInstance.ToLocal();

       And here is a really nice discuss you might be interested in

       http://forums.silverlight.net/forums/p/87574/204059.aspx

    Best Regards 

    Friday, August 6, 2010 1:45 AM