Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do you Change from string to double and complete the subtraction?

VB
localhour = Hidden1.Value.ToString
       UTChour = DateTime.UtcNow.ToString("HH")
       localTimeZone = CDbl(localhour) - CDbl(UTChour)


Hidden1 is coming from a Javascript script:

XML
<script type="text/javascript">
        var localTime = new Date();
        var hours = localTime.getHours();
        document.getElementById("<%=Hidden1.ClientID%>").value = hours;
    </script>


<input id="Hidden1" type="hidden" runat="server" />
Posted
Updated 6-Apr-14 7:30am
v3
Comments
Abinash_Sahoo 6-Apr-14 13:42pm    
Are you using VB.NET? what's the error are you getting?

0) Don't ToString the UtcNow, just access the Hour property.
1) Why are you ToStringing Hidden1.Value ? What type is it?
2) Why are you trying to do this? Are you trying to get the UTC offset?
 
Share this answer
 
this is my solution:

-JavaScript Code
HTML
<script type="text/javascript">
        var localTime = new Date();
        var h = localTime.getHours();
        document.getElementById("<%=Hidden1.ClientID%>").value = h;
</script>


-HTML
ASP.NET
<asp:hiddenfield id="Hidden1" value="0" runat="server" xmlns:asp="#unknown" />


-Behind Code for C#
C#
string localHour = Hidden1.Value.ToString();
string UTChour = DateTime.UtcNow.ToString("HH");
int diffTime = Convert.ToInt32(localHour) - Convert.ToInt32(UTChour);



Hope it will help you.,

God Bless.
 
Share this answer
 
Try this:
C#
using System;

public class Program
{
    public static void Main()
    {
        int UTChour = DateTime.UtcNow.Hour;
        int localhour = DateTime.Now.Hour;
        int hourDiff = localhour - UTChour;
        Console.WriteLine(hourDiff);
    }
}

Refer more: DateTime.UtcNow Property[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900