1
- using System ;
1
+ using System ;
2
2
3
3
public class Class1
4
4
{
@@ -44,30 +44,21 @@ private static void ConvertUsingDateTime()
44
44
// Convert UTC to DateTime value
45
45
sourceTime = new DateTimeOffset ( baseTime , TimeSpan . Zero ) ;
46
46
targetTime = sourceTime . DateTime ;
47
- Console . WriteLine ( "{0} converts to {1} {2}" ,
48
- sourceTime ,
49
- targetTime ,
50
- targetTime . Kind ) ;
47
+ Console . WriteLine ( $ "{ sourceTime } converts to { targetTime } { targetTime . Kind } ") ;
51
48
52
49
// Convert local time to DateTime value
53
50
sourceTime = new DateTimeOffset ( baseTime ,
54
51
TimeZoneInfo . Local . GetUtcOffset ( baseTime ) ) ;
55
52
targetTime = sourceTime . DateTime ;
56
- Console . WriteLine ( "{0} converts to {1} {2}" ,
57
- sourceTime ,
58
- targetTime ,
59
- targetTime . Kind ) ;
53
+ Console . WriteLine ( $ "{ sourceTime } converts to { targetTime } { targetTime . Kind } ") ;
60
54
61
55
// Convert Central Standard Time to a DateTime value
62
56
try
63
57
{
64
58
TimeSpan offset = TimeZoneInfo . FindSystemTimeZoneById ( "Central Standard Time" ) . GetUtcOffset ( baseTime ) ;
65
59
sourceTime = new DateTimeOffset ( baseTime , offset ) ;
66
60
targetTime = sourceTime . DateTime ;
67
- Console . WriteLine ( "{0} converts to {1} {2}" ,
68
- sourceTime ,
69
- targetTime ,
70
- targetTime . Kind ) ;
61
+ Console . WriteLine ( $ "{ sourceTime } converts to { targetTime } { targetTime . Kind } ") ;
71
62
}
72
63
catch ( TimeZoneNotFoundException )
73
64
{
@@ -85,10 +76,7 @@ private static void ConvertUtcTime()
85
76
// <Snippet6>
86
77
DateTimeOffset utcTime1 = new DateTimeOffset ( 2008 , 6 , 19 , 7 , 0 , 0 , TimeSpan . Zero ) ;
87
78
DateTime utcTime2 = utcTime1 . UtcDateTime ;
88
- Console . WriteLine ( "{0} converted to {1} {2}" ,
89
- utcTime1 ,
90
- utcTime2 ,
91
- utcTime2 . Kind ) ;
79
+ Console . WriteLine ( $ "{ utcTime1 } converted to { utcTime2 } { utcTime2 . Kind } ") ;
92
80
// The example displays the following output to the console:
93
81
// 6/19/2008 7:00:00 AM +00:00 converted to 6/19/2008 7:00:00 AM Utc
94
82
// </Snippet6>
@@ -104,10 +92,7 @@ private static void ConvertLocalTime()
104
92
if ( utcTime1 . Offset . Equals ( TimeZoneInfo . Local . GetUtcOffset ( utcTime1 . DateTime ) ) )
105
93
utcTime2 = DateTime . SpecifyKind ( utcTime2 , DateTimeKind . Local ) ;
106
94
107
- Console . WriteLine ( "{0} converted to {1} {2}" ,
108
- utcTime1 ,
109
- utcTime2 ,
110
- utcTime2 . Kind ) ;
95
+ Console . WriteLine ( $ "{ utcTime1 } converted to { utcTime2 } { utcTime2 . Kind } ") ;
111
96
// The example displays the following output to the console:
112
97
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
113
98
// </Snippet7>
@@ -134,28 +119,19 @@ private static void CallConversionFunction()
134
119
// Convert UTC time
135
120
DateTimeOffset utcTime = new DateTimeOffset ( timeComponent , TimeSpan . Zero ) ;
136
121
returnedDate = ConvertFromDateTimeOffset ( utcTime ) ;
137
- Console . WriteLine ( "{0} converted to {1} {2}" ,
138
- utcTime ,
139
- returnedDate ,
140
- returnedDate . Kind ) ;
122
+ Console . WriteLine ( $ "{ utcTime } converted to { returnedDate } { returnedDate . Kind } ") ;
141
123
142
124
// Convert local time
143
125
DateTimeOffset localTime = new DateTimeOffset ( timeComponent ,
144
126
TimeZoneInfo . Local . GetUtcOffset ( timeComponent ) ) ;
145
127
returnedDate = ConvertFromDateTimeOffset ( localTime ) ;
146
- Console . WriteLine ( "{0} converted to {1} {2}" ,
147
- localTime ,
148
- returnedDate ,
149
- returnedDate . Kind ) ;
128
+ Console . WriteLine ( $ "{ localTime } converted to { returnedDate } { returnedDate . Kind } ") ;
150
129
151
130
// Convert Central Standard Time
152
131
DateTimeOffset cstTime = new DateTimeOffset ( timeComponent ,
153
132
TimeZoneInfo . FindSystemTimeZoneById ( "Central Standard Time" ) . GetUtcOffset ( timeComponent ) ) ;
154
133
returnedDate = ConvertFromDateTimeOffset ( cstTime ) ;
155
- Console . WriteLine ( "{0} converted to {1} {2}" ,
156
- cstTime ,
157
- returnedDate ,
158
- returnedDate . Kind ) ;
134
+ Console . WriteLine ( $ "{ cstTime } converted to { returnedDate } { returnedDate . Kind } ") ;
159
135
// The example displays the following output to the console:
160
136
// 6/19/2008 7:00:00 AM +00:00 converted to 6/19/2008 7:00:00 AM Utc
161
137
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
@@ -169,10 +145,7 @@ private static void ConvertUtcToDateTimeOffset()
169
145
DateTime utcTime1 = new DateTime ( 2008 , 6 , 19 , 7 , 0 , 0 ) ;
170
146
utcTime1 = DateTime . SpecifyKind ( utcTime1 , DateTimeKind . Utc ) ;
171
147
DateTimeOffset utcTime2 = utcTime1 ;
172
- Console . WriteLine ( "Converted {0} {1} to a DateTimeOffset value of {2}" ,
173
- utcTime1 ,
174
- utcTime1 . Kind ,
175
- utcTime2 ) ;
148
+ Console . WriteLine ( $ "Converted { utcTime1 } { utcTime1 . Kind } to a DateTimeOffset value of { utcTime2 } ") ;
176
149
// This example displays the following output to the console:
177
150
// Converted 6/19/2008 7:00:00 AM Utc to a DateTimeOffset value of 6/19/2008 7:00:00 AM +00:00
178
151
// </Snippet1>
@@ -184,10 +157,7 @@ private static void ConvertLocalToDateTimeOffset()
184
157
DateTime localTime1 = new DateTime ( 2008 , 6 , 19 , 7 , 0 , 0 ) ;
185
158
localTime1 = DateTime . SpecifyKind ( localTime1 , DateTimeKind . Local ) ;
186
159
DateTimeOffset localTime2 = localTime1 ;
187
- Console . WriteLine ( "Converted {0} {1} to a DateTimeOffset value of {2}" ,
188
- localTime1 ,
189
- localTime1 . Kind ,
190
- localTime2 ) ;
160
+ Console . WriteLine ( $ "Converted { localTime1 } { localTime1 . Kind } to a DateTimeOffset value of { localTime2 } ") ;
191
161
// This example displays the following output to the console:
192
162
// Converted 6/19/2008 7:00:00 AM Local to a DateTimeOffset value of 6/19/2008 7:00:00 AM -07:00
193
163
// </Snippet2>
@@ -198,10 +168,7 @@ private static void ConvertUnspecifiedToDateTimeOffset1()
198
168
// <Snippet3>
199
169
DateTime time1 = new DateTime ( 2008 , 6 , 19 , 7 , 0 , 0 ) ; // Kind is DateTimeKind.Unspecified
200
170
DateTimeOffset time2 = time1 ;
201
- Console . WriteLine ( "Converted {0} {1} to a DateTimeOffset value of {2}" ,
202
- time1 ,
203
- time1 . Kind ,
204
- time2 ) ;
171
+ Console . WriteLine ( $ "Converted { time1 } { time1 . Kind } to a DateTimeOffset value of { time2 } ") ;
205
172
// This example displays the following output to the console:
206
173
// Converted 6/19/2008 7:00:00 AM Unspecified to a DateTimeOffset value of 6/19/2008 7:00:00 AM -07:00
207
174
// </Snippet3>
@@ -215,10 +182,7 @@ private static void ConvertUnspecifiedToDateTimeOffset2()
215
182
{
216
183
DateTimeOffset time2 = new DateTimeOffset ( time1 ,
217
184
TimeZoneInfo . FindSystemTimeZoneById ( "Central Standard Time" ) . GetUtcOffset ( time1 ) ) ;
218
- Console . WriteLine ( "Converted {0} {1} to a DateTime value of {2}" ,
219
- time1 ,
220
- time1 . Kind ,
221
- time2 ) ;
185
+ Console . WriteLine ( $ "Converted { time1 } { time1 . Kind } to a DateTime value of { time2 } ") ;
222
186
}
223
187
// Handle exception if time zone is not defined in registry
224
188
catch ( TimeZoneNotFoundException )
@@ -238,10 +202,7 @@ private static void ConvertUsingLocalTimeProperty1()
238
202
TimeZoneInfo . Local . GetUtcOffset ( sourceDate ) ) ;
239
203
DateTime localTime2 = localTime1 . LocalDateTime ;
240
204
241
- Console . WriteLine ( "{0} converted to {1} {2}" ,
242
- localTime1 ,
243
- localTime2 ,
244
- localTime2 . Kind ) ;
205
+ Console . WriteLine ( $ "{ localTime1 } converted to { localTime2 } { localTime2 . Kind } ") ;
245
206
// The example displays the following output to the console:
246
207
// 6/19/2008 7:00:00 AM -07:00 converted to 6/19/2008 7:00:00 AM Local
247
208
// </Snippet10>
@@ -257,19 +218,13 @@ private static void ConvertUsingLocalTimeProperty2()
257
218
originalDate = new DateTimeOffset ( 2008 , 6 , 18 , 7 , 0 , 0 ,
258
219
new TimeSpan ( - 5 , 0 , 0 ) ) ;
259
220
localDate = originalDate . LocalDateTime ;
260
- Console . WriteLine ( "{0} converted to {1} {2}" ,
261
- originalDate ,
262
- localDate ,
263
- localDate . Kind ) ;
221
+ Console . WriteLine ( $ "{ originalDate } converted to { localDate } { localDate . Kind } ") ;
264
222
// Convert time originating in a different time zone
265
223
// so local time zone's adjustment rules are applied
266
224
originalDate = new DateTimeOffset ( 2007 , 11 , 4 , 4 , 0 , 0 ,
267
225
new TimeSpan ( - 5 , 0 , 0 ) ) ;
268
226
localDate = originalDate . LocalDateTime ;
269
- Console . WriteLine ( "{0} converted to {1} {2}" ,
270
- originalDate ,
271
- localDate ,
272
- localDate . Kind ) ;
227
+ Console . WriteLine ( $ "{ originalDate } converted to { localDate } { localDate . Kind } ") ;
273
228
// The example displays the following output to the console,
274
229
// when you run it on a machine that is set to Pacific Time (US & Canada):
275
230
// 6/18/2008 7:00:00 AM -05:00 converted to 6/18/2008 5:00:00 AM Local
@@ -282,10 +237,7 @@ private static void PerformUtcAndTypeConversion()
282
237
// <Snippet12>
283
238
DateTimeOffset originalTime = new DateTimeOffset ( 2008 , 6 , 19 , 7 , 0 , 0 , new TimeSpan ( 5 , 0 , 0 ) ) ;
284
239
DateTime utcTime = originalTime . UtcDateTime ;
285
- Console . WriteLine ( "{0} converted to {1} {2}" ,
286
- originalTime ,
287
- utcTime ,
288
- utcTime . Kind ) ;
240
+ Console . WriteLine ( $ "{ originalTime } converted to { utcTime } { utcTime . Kind } ") ;
289
241
// The example displays the following output to the console:
290
242
// 6/19/2008 7:00:00 AM +05:00 converted to 6/19/2008 2:00:00 AM Utc
291
243
// </Snippet12>
0 commit comments