I have a program that runs the following code on C#:
TimeZoneInfo localZone = TimeZoneInfo.Local;
string timeZone = TimeZoneInfo.FindSystemTimeZoneById(localZone.Id).ToString();
MessageBox.Show("Local Time Zone ID: " + timeZone);
When I run this, I got the following exception:
System.TimeZoneNotFoundException: The time zone ID 'Malay Peninsula Standard Time' was not found on the local computer.
I made a slight modification on the code and used this line:
TimeZoneInfo localZone = TimeZoneInfo.Local;
MessageBox.Show("Local Time Zone ID: " + localZone.StandardName);
And this time I got no exception, and I got the popup message with the time zone "Malay Peninsula Standard Time"
Why the first fragment of code is not working?
After some time (days), I finally found out what was happening.
Debugging the code, I see that TimeZoneInfo.Local.Id was retrieving the following value:
Malay Peninsula Standard Time
I made some investigation, and found out that all the time zones for the server are stored on this registry key:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones\
If you browse through them, you will see that no key is called "Malay Peninsula Standard Time", the value that is for that time zone is "Singapore Standard Time". The whole information for that time zone is the following:
ID: Singapore Standard Time
Display Name: (GMT+08:00) Kuala Lumpur, Singapore
Standard Name: Malay Peninsula Standard Time
Daylight Name: Malay Peninsula Daylight Time ***Does Not Have Daylight Saving Time***
Offset from UTC: 8 hours, 0 minutes
Number of adjustment rules: 0
So, as you see, the ID that I was looking for did not exist, and that's why I got that exception. I renamed the registry key to "Malay Peninsula Standard Time" and the problem was gone.
Related
I've written the following code to convert the DateTimeOffset to CST DateTime
var bookingDateInCst = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(itemRequest.BookingDate, "Central Standard Time");
This works on my local machine, but when I deployed it on PCF cloud environment I get the following error
"The time zone ID 'Central Standard Time' was not found on the local computer."
How to fix it?
I've used TZConvert utility, by reading this block
https://devblogs.microsoft.com/dotnet/cross-platform-time-zones-with-net-core/
It helped me fix the issue using following code:
var cstTimeZoneInfo = TZConvert.GetTimeZoneInfo("Central Standard Time");
var bookingDateInCst =TimeZoneInfo.ConvertTimeFromUtc(itemRequest.BookingDate.UtcDateTime, cstTimeZoneInfo);
I have configured a template with an exploration date:
Get-AipServiceTemplateProperty -TemplateId 7a3e9ebd-a14e-4520-ba34-434029030633 -ContentExpirationDate -ContentExpirationOption | Format-List
Key : ContentExpirationOption
Value : OnDate
Key : ContentExpirationDate
Value : 12/25/2020 11:56:00 AM
And then I set protection to file with this template
ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor("7a3e9ebd-a14e-4520-ba34-434029030633");
The file successfully encrypted and the permission is set but it looks like the exploration date didn't work. When I open the file Word doesn't show me until when the file is valid.
For this problem, as it shows 12/25/2020 11:56:00 AM for the key ContentExpirationDate but you didn't find it work. So please check the the time zone of the expiration date, check if it matches UTC time zone and doesn't match your local time zone.
I am having problem in creating a shipment in MAC Operating System. In windows operating system the website works fine. Any Help would be appreciated
Thanks.
Code:
createOrUpdateShipment: function (shipmentHeader) {
----------
var tzm= (/\((.*)\)/.exec(new Date().toString())[1]);
return $http.post('/shipment/CreateOrUpdateShipment?tzm='+tzm, shipmentHeader)
},
And in the Controller
public ActionResult CreateOrUpdateShipment(ShipmentInfo shipmentInfo, string tzm)
TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(tzm);
shipmentInfo.ServiceInfo.READYDATETYPE = TimeZoneInfo.ConvertTime(shipmentInfo.ServiceInfo.READYDATETYPE,tzi);
Below Error I am getting when I try to create the shipment using MAC Operating System
Getting error time zone not found exception. The time zone ID 'CST' was not found
Time zones in .NET are identified by their full names, not their abbreviations. You are making a call to FindSystemTimeZoneById. This API would expect "Central Standard Time", not "CST".
I would guess that your Mac client is sending tzm=CST and your Windows client is sending tzm=Central+Standard+Time. Your server only works when the client spells it out.
I have used Icalendar in my project, I am facing a weird issue for recurrence request. I am passing DTSTART 28 march but calendar is generated for 29 march. recurrence is untill 30th march. My icalendar is as follow
BEGIN:VCALENDAR
PRODID:-//Team Test
VERSION:2.0
METHOD:REQUEST
BEGIN:VTIMEZONE
TZID:Asia/Kolkata
BEGIN:STANDARD
TZOFFSETFROM:+0530
TZOFFSETTO:+0530
TZNAME:IST
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART:20160328T223000Z
DTSTAMP:20160321T140058Z
DTEND:20160328T230000Z
RRULE:FREQ=DAILY;UNTIL=20160330T173000Z
LOCATION:
UID:request180107lvis.support#mycompanydomain.com
DESCRIPTION:Requester : Yadav, Chandikumar +() +919876543210
X-ALT-DESC;FMTTYPE=text/html:Requester : Yadav, Chandikumar +() +919876543210
SUMMARY:Conference Testing
ORGANIZER:MAILTO:test.support#mycompanydomain.com
ATTENDEE;ROLE=REQ-PARTICIPANT;CN="";RSVP=TRUE:mailto:chandikumar.yadav#mycompanydomain.com
ATTENDEE;ROLE=REQ-PARTICIPANT;CN="";RSVP=TRUE:mailto:jatin.kolhe#mycompanydomain.com
ATTENDEE;PARTSTAT=ACCEPTED;CN="Testing":mailto:test.lvis.support#mycompanydomain.com
ATTACH;FMTTYPE=message/rfc822:D:\Projects\abc.pdf
BEGIN:VALARM
TRIGGER:-PT15M
ACTION:DISPLAY
DESCRIPTION:Reminder
END:VALARM
END:VEVENT
END:VCALENDAR
I have passed DTSTART, DTEND and UNTIL. Unable to figure out where is the problem.
You specified:
20160328T223000Z
Based on the rest of the iCalendar document, I'm guessing you are actually in this timezone:
Asia/Kolkata
Since that is UTC+5:30, I'm guessing the newly generated time is:
2016-03-29 04:00:00 in your own timezone
If you want to specify the time in your timezone currenctly, make sure you add TZID to all your DATE-TIME fields, such as DTSTART and don't include the Z at the end of the timestamp. (Z stands for Zulu time, which is UTC)
I am using the following code to write the Date Modified time of a Directory to a label
string selectedPath = comboBox1.SelectedItem.ToString();
DateTime lastdate = Directory.GetLastWriteTime(selectedPath);
datemodified.Text = lastdate.ToString();
It returns the date 12/31/1600 7:00:00 PM which I have no clue where it is getting that date from. Can anyone help me understand why it is returning that date and how I can fix it? I'm using .NET 3.5
From the documentation:
If the directory described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.
So presumably your time zone is UTC-5 (in January), and the directory doesn't exist...
first thought is that of is your time set correctly. Second thought is to right click on that folder and see what it says in properties. Lastly I'd make new test folder and run that bit of GetLastWriteTime tests on it so you know what you are getting back.
GetLastWriteTime not always return reliable date time, use this
string selectedPath = comboBox1.SelectedItem.ToString();
DateTime now = DateTime.Now;
TimeSpan localOffset = now - now.ToUniversalTime();
DateTime lastdate = File.GetLastWriteTimeUtc(selectedPath) + localOffset;
datemodified.Text = lastdate.ToString();
Old question, but today I faced this issue. That particular date is also returned when your path is invalid or the file doesn't exists, because there is no built in exception in any of those cases.
An easy way to test for file not found with the result of GetLastWriteTime()/GetLastWriteTimeUtc() without hardcoding the sentinel epoch date/times that are used to indicate a file/dir not found condition, is as follows:
// ##### Local file time version #####
DateTime fileTimeEpochLocal=DateTime.FromFileTime(0);
// Use File.GetLastWriteTime(pathname) for files
// and Directory.GetLastWriteTime(pathname) for directories
DateTime lastWriteTime=Directory.GetLastWriteTime(selectedPath);
// Check for a valid last write time
if (lastWriteTime!=fileTimeEpochLocal) // File found
DoSomethingWith(selectedPath,lastWriteTime);
else // File not found
HandleFileNotFound(selectedPath);
// ##### UTC file time version #####
DateTime fileTimeEpochUtc=DateTime.FromFileTimeUtc(0);
// Use File.GetLastWriteTimeUtc(pathname) for files
// and Directory.GetLastWriteTimeUtc(pathname) for directories
DateTime lastWriteTimeUtc=Directory.GetLastWriteTimeUtc(selectedPath);
// Check for a valid last write time
if (lastWriteTimeUtc!=fileTimeEpochUtc) // File found
DoSomethingWith(selectedPath,lastWriteTimeUtc);
else // File not found
HandleFileNotFound(selectedPath);
In .net core, you will need to get the absolute path of the file.
Add reference to Microsoft.Extensions.Hosting and inject that into your constructor.
The ContentRootPath property will be your web root.
Grab your server path
var Files = FIO.Directory.GetFiles("Unzipped");
This will be your actual path
var Path = string.Format(#"{0}\{1}",WebRootPath, Files[0]);
var CreationDate = File.GetLastWriteTime(Path);