c#


how to get TimeZoneInfo short name


Is there any method to get the 3 char code from
System.TimeZoneInfo.Local
?
e.g. EDT instead of Eastern Daylight time etc.
Unfortunately, there is no easy built-in way of doing this that I know of. However, you could put something together yourself. Here's an example:
public static class TimeZoneInfoExtensions {
public static string Abbreviation(this TimeZoneInfo Source) {
var Map = new Dictionary<string, string>()
{
{"eastern standard time","est"},
{"mountain standard time","mst"},
{"central standard time","cst"},
{"pacific standard time","pst"}
//etc...
};
return Map[Source.Id.ToLower()].ToUpper();
}
}
Use as follows:
string CurrentTimeZoneAbbreviation = System.TimeZoneInfo.Local.Abbreviation();
If you need more conversions you could just plug them into the Map dictionary.
TimeZoneInfo.Id will be a string matching a given key in [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones]. If you can find a matching database online, containing the same Ids as well as the abbreviations, it would be possible to quickly extract and import the pairs (with regular expressions, for example) and drop those into the Map dictionary.
You can write something like:
var abbr = System.TimeZoneInfo.Local.TimeZoneAbbr();
And the helper for it:
public static class ConvertionHelper
{
public static String TimeZoneAbbr(this TimeZoneInfo zone)
{
var zoneName = zone.Id;/* zone.IsDaylightSavingTime(DateTime.UtcNow)
? zone.DaylightName
: zone.StandardName;*/
var zoneAbbr = zoneName.CapitalLetters();
return zoneAbbr;
}
public static String CapitalLetters(this String str)
{
return str.Transform(c => Char.IsUpper(c)
? c.ToString(CultureInfo.InvariantCulture)
: null);
}
private static String Transform(this String src, Func<Char, String> transformation)
{
if (String.IsNullOrWhiteSpace(src))
{
return src;
}
var result = src.Select(transformation)
.Where(res => res != null)
.ToList();
return String.Join("", result);
}
}

Related Links

How to restrict users to a tab
SqlCeException Not enough storage
Using Unity configuration file, how to register FluentValidation Validator Implementation with concrete in a different assembly
Call C# method from javascript drag and drop event
Customize order by in Gridview rows
how to display enum with set of special charaters as V1.0, V2.0 and V3.0
Get and object to orbit around another when button is pressed C# XNA
Automating Powerpoint Data from Microsoft Excel
How to get the value of a property of a class in a non executing assembly through reflection
why is log4net appearing in console and not text file
C# Singleton instance returns null
IOrderedQueryable Skip and Take
Bind control to dynamic collection of key-value pairs
iOS Notifications not sent using PushSharp. No event is raised either
display aspx in iframe and aspx is displaying pdf
ICollectionView's CurrentChanged event not working if we create full property

Categories

HOME
logging
gulp
twitter-bootstrap
ftp
skypedeveloper
ebay-api
xss
grid
wavefront
wowza
lambda-calculus
minimum
openstack-horizon
game-engine
k-means
jquery-easyui
gpo
datasource
jq
infinite-loop
inline-assembly
oracle-golden-gate
ps
ithit-webdav-server
chartist.js
pydub
visual-studio-community
smart-device
mex
typeclass
pushpad
kundera
arp
andengine
ios-autolayout
loopback
mootools
odp.net
sampling
pyenv
cache-control
azure-vm-scale-set
realloc
blueimp
ssdp
icu
autodesk-data-management
pexpect
libzip
jenkins-2
stanford-nlp-server
flask-socketio
aws-rds
printer-control-language
tsc
pyautogui
computed-properties
jira-agile
mate-desktop
change-password
nsoperationqueue
php-java-bridge
system-integration
sdkman
libgcrypt
jts
personality-insights
android-filterable
eggplant
photogrammetry
genero
chrome-mobile
douglas-peucker
cordova-3
javadb
kss
frisby.js
yosemite
nspopupbutton
dateadd
rda
hotlinking
pidgin
nomachine
autofilter
servicemanager
reference-manual
mmo
blotter
urlfetch
esi
ios6-maps
dancer
yii-cactiverecord
backlight
windows-xp-embedded
mismatch
cinder
virtual-destructor
file-storage
time-management
authkit
projectgen
hotfix

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App