2011-10-30 4 views
0

나는 지금은 사용자 다음 정상 회담을 인도에서 질문이있는 경우와 같이, 사용자의 시간대 또는 사용자의 컴퓨터 모델에 따라 시간을 표시하려면, 데이터베이스 UTC의 날짜 시간이 사용자 에 미국가는 경우 사용자 다음은 미국에 따라 표시, 인도에 따라 제출 한 날짜를 볼 수 있으며 사용자 B는 중국에있는 경우 다음 그는 따라서 그 질문을 볼 수 있습니다 ~ 치 na. C# 또는 javascript를 통해 어떻게 할 수 있습니까? 누구든지 저를 도울 수 있습니다.날짜 시간은 고객의 위치에 따라

+1

가능한 복제본 [C# UTC - 사용자 현지 시간] (http://stackoverflow.com/questions/4066275/c-sharp-utc-to-users-local-time) – Damith

답변

1

당신 브라우저에서 필요한 정보를 수집하기 위해 자바 스크립트를 사용해야합니다 - 당신은 당신이 설정을 다시 사용할 수있는 TimeZone/TimeZoneInfo이 UTC를 조정 할 수 있습니다이 정보가있을 때 http://www.pageloom.com/automatic-timezone-detection-with-javascript

볼이 부분을 DateTime 값.

더 쉬운 또 다른 옵션은 jQuery plugin called TimeAgo입니다.
자세한 내용은 참조하십시오 C# UTC to Users Local Time

0

당신은 자바 스크립트를 사용하여 .. 이런 식으로 할 수 .....

이 코드는 .... 당신이 클라이언트의 시간대가 표준 형식으로 오프셋 줄 것이다

 <script type="text/javascript"> 
     // Original script by Josh Fraser (http://www.onlineaspect.com) 
     // Some customization applied in this script code 
     var minutes; 
     function calculate_time_zone() { 
      var rightNow = new Date(); 
      var jan1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0); // jan 1st 
      var june1 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0); // june 1st 
      var temp = jan1.toGMTString(); 
      var jan2 = new Date(temp.substring(0, temp.lastIndexOf(" ") - 1)); 
      temp = june1.toGMTString(); 
      var june2 = new Date(temp.substring(0, temp.lastIndexOf(" ") - 1)); 
      var std_time_offset = (jan1 - jan2)/(1000 * 60 * 60); 
      var daylight_time_offset = (june1 - june2)/(1000 * 60 * 60); 
      var dst; 
      if (std_time_offset == daylight_time_offset) { 
       dst = "0"; // daylight savings time is NOT observed 
      } else { 
       // positive is southern, negative is northern hemisphere 
       var hemisphere = std_time_offset - daylight_time_offset; 
       if (hemisphere >= 0) 
        std_time_offset = daylight_time_offset; 
       dst = "1"; // daylight savings time is observed 
      } 
      var i; 
     // Here set the value of hidden field to the ClientTimeZone. 
         minutes = convert(std_time_offset); 
      TimeField = document.getElementById("HiddenFieldClientTime"); 
      TimeField.value = minutes; 
      alert('your time zone is ' + minutes);  
     } 
     // This function is to convert the timezoneoffset to Standard format 
     function convert(value) { 
      var hours = parseInt(value); 
      value -= parseInt(value); 
      value *= 60; 
      var mins = parseInt(value); 
      value -= parseInt(value); 
      value *= 60; 
      var secs = parseInt(value); 
      var display_hours = hours; 
      // handle GMT case (00:00) 
      if (hours == 0) { 
       display_hours = "00"; 
      } else if (hours > 0) { 
       // add a plus sign and perhaps an extra 0 
       display_hours = (hours < 10) ? "+0" + hours : "+" + hours; 
      } else { 
       // add an extra 0 if needed 
       display_hours = (hours > -10) ? "-0" + Math.abs(hours) : hours; 
      } 
      mins = (mins < 10) ? "0" + mins : mins; 
      return display_hours + ":" + mins; 
     } 
     // Adding the function to onload event of document object 
     onload = calculate_time_zone; 
</script> 

난 당신이 pls는 this link

통해 이동이 하나 time detection

0123을 살펴 권장
관련 문제