Posts

Showing posts with the label DateTime

How to Get/Set date time according to Different Time zones in C#

Image
Download code example In an Asp.net application I have developed a Forum in which I have requirement to show date and time according to the time zone of PC on which it is running, I had searched for too many examples on but all are using too complex java scripts and other methods to convert time into local time zone. Finally I decided to make my own solution for this problem My solution is using “TimeZoneInfo” to convert the data to local time zone, this class allow me to convert time according to any time zone, but again I got another problem which is how to take time zone of browser. Again I search on net and finally come out with a code. <script language="javascript" type="text/javascript">     function genarateDateValue()     {                      var d = new Date()             ...

How to use DateDiff Function in C#

How to use DateDiff Function in C#. As earlier in ASP and VB6 we have too may conversion and date time functions. After working for so many years, we all had become habitual of working with the same. We have almost all the functions available in c#. But, sometimes lost control on some functions. Like for datediff WE have to write so much code in C#. At this moment we just remember functions of VB. Now, say thanks to Microsoft… What we can use is:- Add a reference of Microsoft.VisualBasic and access the DateDiff function like following ex. long nYears = Microsoft.VisualBasic.DateAndTime.DateDiff(Microsoft.VisualBasic.DateInterval.Year, dt, dtNow, Microsoft.VisualBasic.FirstDayOfWeek.System, Microsoft.VisualBasic.FirstWeekOfYear.System); By using the reference of visual basic you can use any function of Visual Basic or vice-versa.