Customizing the Self-Service Portal Source Code Example #1–Displaying the Local Time on the Portal instead of UTC/GMT

Customizing the Self-Service Portal Source Code Example #1–Displaying the Local Time on the Portal instead of UTC/GMT

  • Comments 25
  • Likes

The self-service portal right now always displays datetime values in GMT since we don’t have a way to know which time zone the requesting user is in.  We try to make it clear that the datetime is in GMT time zone like this:

image

image

Unfortunately, I think a lot of end users don’t know what GMT is and even if they do it is a pain to figure out what the local time is from GMT (is it minus 7 hours or 8 hours right now?  what is 4:45 PM minus 7 hours?).  So – for those customers that have the majority or all of their users in a particular time zone you may want to change this behavior so that it shows the local time.  There are three places in the code that you need to modify.  They are in the file called TimeHelper.cs.

public static DateTime GetTimeInUtc(DateTime localTime)
{
    if (localTime.Kind == DateTimeKind.Utc)
    {
        return localTime;
    }

    return localTime.ToUniversalTime();
}


public static string GetTimeAsStringInUtc(DateTime localTime)
{
    if (localTime.Kind == DateTimeKind.Utc)
    {
        return string.Format(CommonResources.TimeInGMT, localTime.ToString());
    }

    return string.Format(CommonResources.TimeInGMT, localTime.ToUniversalTime().ToString());
}

public static string GetTimeAsStringInUtc(DateTime localTime, string format)
{
    if (localTime.Kind == DateTimeKind.Utc)
    {
        return string.Format(CommonResources.TimeInGMT, localTime.ToString(format));
    }

    return string.Format(CommonResources.TimeInGMT, localTime.ToUniversalTime().ToString(format));
}

 

You need to change these two lines to remove the .ToUniversalTime() function call so that it reads:

return localTime;

return string.Format(CommonResources.TimeInGMT, localTime.ToString());
return string.Format(CommonResources.TimeInGMT, localTime.ToString(format));

Then just to make sure that you are being clear to the users what time zone you are displaying you should change the TimeInGMT string resource in CommonResources.resx to indicate the time zone.  For example change:

image

to:

image

Make sure you leave the {0} in there.  That is the place in the string in which the actual datetime value will be substituted by the Format function call.

Keep in mind that this will display the local time of the portal server and will never show the local time of the user requesting the page.

Once you have made these changes build and deploy the portal as described in the documentation that accompanies the portal source download.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • I can see you're heavily working on the Portal based on the last posts... that's great! :)

    I'm going to implement this soon!

    Thanks!

  • Travis we just came across this as a requirement and 20 minutes later you post this up. Great stuff.

    We've had a few issues with Portal v 2.0 (the buttons are transparent so we can't see the text on them, the web part that displays reset password, request software etc. is not re-used from the master template so multiple changes are required to remove "reset password" for example. but we've got it in and it looks great!

  • Thanks Travis, this is a life saver.

  • Hi Travis,

    is there any easy way to change the time

  • shumail - what do you mean by change the time?  You want to show it for some other time zone besides UTC/GMT or the local time of the server?

  • Hi travis

    i have scsm sp1 workflow generates multiple emails at different times

  • travis me want to show server local time on self service portal.

  • @shumail - you just need to make the modifications described in this blog post then.

  • Hi travis,

    Can we integrate SCSM through IVR or submit incident thorugh IVR or voice mail

  • @shumail -

    Its probably possible to integrate with an IVR system in some ways using the SCSM SDK.

  • Travis can you give us some hint or ways to integrate SCSM with any IVR

  • Please explane me anybody, where i can find TimeHelper.cs.

  • @Guest -

    TimeHelper.cs is one of the files that is available for download from in the portal source code package.  More info:

    blogs.technet.com/.../portal-source-code-with-multi-language-support-now-released.aspx

  • Hello, Travis. I have tried to make that that is described on the portal and it has turned out nothing. I have installed Source Code and have changed file TimeHelper.cs as is described above. Further I have opened CommonResources.resx and have changed GMT on U.S. Central Time. Nothing changed, time is shown in GMT format. Where is my error?

  • @Crush - did you deploy the modified version of the portal as described in the portal source code documentation?