@@ -61,7 +61,20 @@ public static DateTime GetStartTimeOfMonth(DateTime date)
6161 public static long GetStartTimestampOfMonth ( DateTime date )
6262 {
6363 var time = GetStartTimeOfMonth ( date ) ;
64- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
64+ return DateTimeToUnixTimeSeconds ( time ) ;
65+ }
66+
67+ /// <summary>
68+ /// 获取指定日期所在月的开始时间戳(基于设置时区)
69+ /// </summary>
70+ /// <param name="date">指定日期</param>
71+ /// <returns>所在月1号零点时间戳(秒) + 时区偏移</returns>
72+ /// <remarks>
73+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
74+ /// </remarks>
75+ public static long GetStartTimestampOfMonthWithTimeZone ( DateTime date )
76+ {
77+ return TimeToSecondsWithTimeZone ( GetStartTimeOfMonth ( date ) ) ;
6578 }
6679
6780 /// <summary>
@@ -93,7 +106,20 @@ public static DateTime GetEndTimeOfMonth(DateTime date)
93106 public static long GetEndTimestampOfMonth ( DateTime date )
94107 {
95108 var time = GetEndTimeOfMonth ( date ) ;
96- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
109+ return DateTimeToUnixTimeSeconds ( time ) ;
110+ }
111+
112+ /// <summary>
113+ /// 获取指定日期所在月的结束时间戳(基于设置时区)
114+ /// </summary>
115+ /// <param name="date">指定日期</param>
116+ /// <returns>所在月最后一天23:59:59的时间戳(秒) + 时区偏移</returns>
117+ /// <remarks>
118+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
119+ /// </remarks>
120+ public static long GetEndTimestampOfMonthWithTimeZone ( DateTime date )
121+ {
122+ return TimeToSecondsWithTimeZone ( GetEndTimeOfMonth ( date ) ) ;
97123 }
98124
99125 /// <summary>
@@ -108,7 +134,19 @@ public static long GetEndTimestampOfMonth(DateTime date)
108134 public static long GetNextMonthStartTimestamp ( )
109135 {
110136 var time = GetNextMonthStartTime ( ) ;
111- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
137+ return DateTimeToUnixTimeSeconds ( time ) ;
138+ }
139+
140+ /// <summary>
141+ /// 获取下月开始时间戳(基于设置时区)
142+ /// </summary>
143+ /// <returns>下月1号零点时间戳(秒) + 时区偏移</returns>
144+ /// <remarks>
145+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
146+ /// </remarks>
147+ public static long GetNextMonthStartTimestampWithTimeZone ( )
148+ {
149+ return TimeToSecondsWithTimeZone ( GetNextMonthStartTime ( ) ) ;
112150 }
113151
114152 /// <summary>
@@ -138,7 +176,19 @@ public static DateTime GetNextMonthEndTime()
138176 public static long GetNextMonthEndTimestamp ( )
139177 {
140178 var time = GetNextMonthEndTime ( ) ;
141- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
179+ return DateTimeToUnixTimeSeconds ( time ) ;
180+ }
181+
182+ /// <summary>
183+ /// 获取下月结束时间戳(基于设置时区)
184+ /// </summary>
185+ /// <returns>下月最后一天23:59:59的时间戳(秒) + 时区偏移</returns>
186+ /// <remarks>
187+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
188+ /// </remarks>
189+ public static long GetNextMonthEndTimestampWithTimeZone ( )
190+ {
191+ return TimeToSecondsWithTimeZone ( GetNextMonthEndTime ( ) ) ;
142192 }
143193
144194 /// <summary>
@@ -190,7 +240,19 @@ public static DateTime GetMonthStartTime()
190240 public static long GetMonthStartTimestamp ( )
191241 {
192242 var time = GetMonthStartTime ( ) ;
193- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
243+ return DateTimeToUnixTimeSeconds ( time ) ;
244+ }
245+
246+ /// <summary>
247+ /// 获取本月开始时间戳(基于设置时区)
248+ /// </summary>
249+ /// <returns>本月1号零点时间戳(秒) + 时区偏移</returns>
250+ /// <remarks>
251+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
252+ /// </remarks>
253+ public static long GetMonthStartTimestampWithTimeZone ( )
254+ {
255+ return TimeToSecondsWithTimeZone ( GetMonthStartTime ( ) ) ;
194256 }
195257
196258 /// <summary>
@@ -213,6 +275,18 @@ public static DateTime GetMonthEndTime()
213275 public static long GetMonthEndTimestamp ( )
214276 {
215277 var time = GetMonthEndTime ( ) ;
216- return new DateTimeOffset ( time , CurrentTimeZone . GetUtcOffset ( time ) ) . ToUnixTimeSeconds ( ) ;
278+ return DateTimeToUnixTimeSeconds ( time ) ;
279+ }
280+
281+ /// <summary>
282+ /// 获取本月结束时间戳(基于设置时区)
283+ /// </summary>
284+ /// <returns>本月最后一天23:59:59的时间戳(秒) + 时区偏移</returns>
285+ /// <remarks>
286+ /// 返回值 = 标准Unix时间戳 + 时区偏移秒数
287+ /// </remarks>
288+ public static long GetMonthEndTimestampWithTimeZone ( )
289+ {
290+ return TimeToSecondsWithTimeZone ( GetMonthEndTime ( ) ) ;
217291 }
218292}
0 commit comments