Tuesday 1 November 2011

Show-DateTimeFormatInfo.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     This script re-implements and MSDN sample that shows 
  4.     the different Date/Time Formatting characters and 
  5.     how they are used in formatting date/time objects. 
  6. .DESCRIPTION 
  7.     This script Creates a date/time object, then shows formatting 
  8.     using the key Date/Time Format strings. 
  9. .NOTES 
  10.     File Name  : Show-DateTimeFormatInfo.ps1 
  11.     Author     : Thomas Lee - tfl@psp.co.uk 
  12.     Requires   : PowerShell Version 2.0 
  13. .LINK 
  14.     This script posted to: 
  15.         http://www.pshscripts.blogspot.com 
  16.     MSDN sample posted to: 
  17.         http://msdn.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx 
  18. .EXAMPLE 
  19.     Left as an exercise for the reader. 
  20.      
  21. #> 
  22.  
  23.  
  24. # Create and initialise a DateTimeFormatInfo associated with the en-US culture. 
  25.  $MyDTFI = (new-object System.Globalization.CultureInfo "en-US", $false ).DateTimeFormat 
  26.  
  27. # Create a DateTime with the Gregorian date January 3, 2002 (year=2002, month=1, day=3) 
  28. # The Gregorian calendar is the default calendar for the en-US culture 
  29. $MyDT = new-object System.DateTime  2002, 1, 3  
  30.  
  31. # Display the format pattern associated with each format character 
  32. "FORMAT  en-US EXAMPLE" 
  33. "CHAR    VALUE OF ASSOCIATED PROPERTY, IF ANY"  
  34. "  d     {0}"          -f $MyDT.ToString("d", $MyDTFI)  
  35. "        {0}    {1}`n" -f $MyDTFI.ShortDatePattern, "(ShortDatePattern)" 
  36. "  D     {0}"          -f $MyDT.ToString("D", $MyDTFI
  37. "        {0}    {1}`n" -f $MyDTFI.LongDatePattern, "(LongDatePattern)" 
  38. "  f     {0}`n"        -f $MyDT.ToString("f", $MyDTFI
  39. "  F     {0}"          -f $MyDT.ToString("F", $MyDTFI
  40. "        {0}    {1}`n" -f $MyDTFI.FullDateTimePattern, "(FullDateTimePattern)" 
  41. "  g     {0}`n"        -f $MyDT.ToString("g", $MyDTFI
  42. "  G     {0}`n"        -f $MyDT.ToString("G", $MyDTFI
  43. "  m     {0}"          -f $MyDT.ToString("m", $MyDTFI
  44. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  45. "  M     {0}"          -f $MyDT.ToString("M", $MyDTFI)  
  46. "        {0}    {1}`n" -f $MyDTFI.MonthDayPattern, "(MonthDayPattern)" 
  47. "  o     {0}`n"        -f $MyDT.ToString("o", $MyDTFI
  48. "  r     {0}"          -f $MyDT.ToString("r", $MyDTFI)  
  49. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  50. "  R     {0}"          -f $MyDT.ToString("R", $MyDTFI)  
  51. "        {0}    {1}`n" -f $MyDTFI.RFC1123Pattern, "(RFC1123Pattern)" 
  52. "  s     {0}"          -f $MyDT.ToString("s", $MyDTFI)  
  53. "        {0}    {1}`n" -f $MyDTFI.SortableDateTimePattern, "(SortableDateTimePattern)" 
  54. "  t     {0}"          -f $MyDT.ToString("t", $MyDTFI)  
  55. "        {0}    {1}`n" -f $MyDTFI.ShortTimePattern, "(ShortTimePattern)" 
  56. "  T     {0}"          -f $MyDT.ToString("T", $MyDTFI)  
  57. "        {0}    {1}`n" -f $MyDTFI.LongTimePattern, "(LongTimePattern)" 
  58. "  u     {0}"          -f $MyDT.ToString("u", $MyDTFI)  
  59. "        {0}    {1}`n" -f $MyDTFI.UniversalSortableDateTimePattern, "(UniversalSortableDateTimePattern)" 
  60. "  U     {0}`n"        -f $MyDT.ToString("U", $MyDTFI
  61. "  y     {0}"          -f $MyDT.ToString("y", $MyDTFI)  
  62. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 
  63. "  Y     {0}"          -f $MyDT.ToString("Y", $MyDTFI)  
  64. "        {0}    {1}`n" -f $MyDTFI.YearMonthPattern, "(YearMonthPattern)" 

1 comment:

mdshell said...

About Date, time formatting characters is discussed. It is technical.




Sample Documents