| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- export function formatDate(dateString) {
- const date = new Date(dateString);
- const day = date.getUTCDate().toString().padStart(2, '0');
- const month = (date.getUTCMonth() + 1).toString().padStart(2, '0'); // getUTCMonth() returns 0-11
- const year = date.getUTCFullYear();
- return `${day}/${month}/${year}`;
- }
- export function formatCouponDate(dateString) {
- if (dateString === null) {
- return '永久';
- }
- // Use the Date object to properly parse the ISO string
- const date = new Date(dateString);
- const day = date.getUTCDate().toString().padStart(2, '0');
- const month = (date.getUTCMonth() + 1).toString().padStart(2, '0');
- const year = date.getUTCFullYear();
- return `${day}/${month}/${year}`;
- }
- export const convertToHKTime = (utcDateTimeString) => {
- const hkDate = new Date(utcDateTimeString).toLocaleString('en-HK', {
- timeZone: 'Asia/Hong_Kong',
- year: 'numeric',
- month: 'numeric',
- day: 'numeric'
- });
- const hkTime = new Date(utcDateTimeString).toLocaleString('en-HK', {
- timeZone: 'Asia/Hong_Kong',
- hour: '2-digit',
- minute: '2-digit',
- second: '2-digit',
- hour12: false
- });
- return { hkDate, hkTime };
- };
- export function formatToChineseDateTime(dateString: string): string {
- const date = new Date(dateString);
- // Add 8 hours for HK timezone
- date.setHours(date.getHours());
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const day = date.getDate();
- const hours = date.getHours();
- const minutes = date.getMinutes();
- // Pad minutes with leading zero if needed
- const paddedMinutes = minutes.toString().padStart(2, '0');
- return `${month}月${day}日 ${hours}:${paddedMinutes}`;
- }
- // Example usage:
- // const utcDateString = "2024-08-22T09:00:00.000Z";
- // const hkTime = convertToHKTime(utcDateString);
- // console.log(hkTime); // Output will be in the format: YYYY/MM/DD/HH/MM/SS
|