File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed
Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -237,7 +237,8 @@ func main() {
237237/// 获取当前时间戳(本地时间格式)
238238#[ tauri:: command]
239239pub fn get_current_timestamp ( ) -> String {
240- chrono:: Local :: now ( ) . format ( "%Y-%m-%d %H:%M:%S" ) . to_string ( )
240+ // 使用 ISO 8601 格式,确保在所有系统上都能正确解析
241+ chrono:: Local :: now ( ) . format ( "%Y-%m-%dT%H:%M:%S" ) . to_string ( )
241242}
242243
243244/// 获取支持的编程语言列表
Original file line number Diff line number Diff line change @@ -34,15 +34,15 @@ export async function getCurrentTimestamp(): Promise<string> {
3434 return await invoke ( "get_current_timestamp" ) ;
3535 } catch ( error ) {
3636 console . error ( "Failed to get current timestamp:" , error ) ;
37- // 回退到前端本地时间
37+ // 回退到前端本地时间,使用 ISO 8601 格式
3838 const now = new Date ( ) ;
3939 const year = now . getFullYear ( ) ;
4040 const month = String ( now . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) ;
4141 const day = String ( now . getDate ( ) ) . padStart ( 2 , "0" ) ;
4242 const hours = String ( now . getHours ( ) ) . padStart ( 2 , "0" ) ;
4343 const minutes = String ( now . getMinutes ( ) ) . padStart ( 2 , "0" ) ;
4444 const seconds = String ( now . getSeconds ( ) ) . padStart ( 2 , "0" ) ;
45- return `${ year } -${ month } -${ day } ${ hours } :${ minutes } :${ seconds } ` ;
45+ return `${ year } -${ month } -${ day } T ${ hours } :${ minutes } :${ seconds } ` ;
4646 }
4747}
4848
Original file line number Diff line number Diff line change @@ -2,7 +2,34 @@ import { useI18n } from "vue-i18n";
22
33export function formatTime ( dateInput : Date | string ) : string {
44 const { t, locale } = useI18n ( ) ;
5- const date = typeof dateInput === "string" ? new Date ( dateInput ) : dateInput ;
5+
6+ let date : Date ;
7+
8+ if ( typeof dateInput === "string" ) {
9+ // 尝试解析时间字符串
10+ let parsedDate : Date | null = null ;
11+
12+ // 尝试直接解析
13+ try {
14+ parsedDate = new Date ( dateInput ) ;
15+ if ( ! isNaN ( parsedDate . getTime ( ) ) ) {
16+ date = parsedDate ;
17+ } else {
18+ // 尝试将空格替换为 T 来解析
19+ const isoStr = dateInput . replace ( " " , "T" ) ;
20+ parsedDate = new Date ( isoStr ) ;
21+ if ( ! isNaN ( parsedDate . getTime ( ) ) ) {
22+ date = parsedDate ;
23+ } else {
24+ return t ( "time.invalid_date" ) ;
25+ }
26+ }
27+ } catch {
28+ return t ( "time.invalid_date" ) ;
29+ }
30+ } else {
31+ date = dateInput ;
32+ }
633
734 // 检查日期是否有效
835 if ( isNaN ( date . getTime ( ) ) ) {
You can’t perform that action at this time.
0 commit comments