File tree Expand file tree Collapse file tree 2 files changed +20
-3
lines changed
Expand file tree Collapse file tree 2 files changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -294,6 +294,7 @@ import { save, confirm } from "@tauri-apps/plugin-dialog";
294294import { snippetApi , initDatabase , clipboardApi } from " ../services/tauri" ;
295295import { toast } from " ../composables/useToast" ;
296296import { useClipboardSettings } from " ../composables/useClipboardSettings" ;
297+ import { getFormattedTimestampForFilename } from " ../utils/time" ;
297298
298299const { t } = useI18n ();
299300
@@ -333,9 +334,7 @@ const exportSnippets = async () => {
333334 const jsonData = JSON .stringify (snippetsForExport , null , 2 );
334335
335336 // 使用 Tauri 的文件对话框保存文件
336- const fileName = ` seekcode-snippets-${
337- new Date ().toISOString ().split (" T" )[0 ]
338- }.json ` ;
337+ const fileName = ` seekcode-snippets-${getFormattedTimestampForFilename ()}.json ` ;
339338
340339 try {
341340 const filePath = await save ({
Original file line number Diff line number Diff line change @@ -49,3 +49,21 @@ export function formatTime(dateInput: Date | string): string {
4949
5050 return date . toLocaleDateString ( locale . value ) ;
5151}
52+
53+ /**
54+ * 生成用于文件名的格式化时间戳
55+ * 格式:YYYY-MM-DDTHH-MM-SS
56+ * 使用本地时间,适合作为文件名
57+ */
58+ export function getFormattedTimestampForFilename (
59+ date : Date = new Date ( )
60+ ) : string {
61+ const year = date . getFullYear ( ) ;
62+ const month = String ( date . getMonth ( ) + 1 ) . padStart ( 2 , "0" ) ;
63+ const day = String ( date . getDate ( ) ) . padStart ( 2 , "0" ) ;
64+ const hours = String ( date . getHours ( ) ) . padStart ( 2 , "0" ) ;
65+ const minutes = String ( date . getMinutes ( ) ) . padStart ( 2 , "0" ) ;
66+ const seconds = String ( date . getSeconds ( ) ) . padStart ( 2 , "0" ) ;
67+
68+ return `${ year } -${ month } -${ day } T${ hours } -${ minutes } -${ seconds } ` ;
69+ }
You can’t perform that action at this time.
0 commit comments