Converting a date to ISO format from PostgreSQL timestamp with time zone in React Native.

export function toISOFormat(dateString: string): string {
// Convert date from format 2024-10-25 14:51:27.056551+03 to ISO format
const match = dateString.match(/^(\d{4}-\d{2}-\d{2}) (\d{2}:\d{2}:\d{2})(?:.\d+)?([+-]\d{2})/);
if (!match) {
throw new Error("Invalid date format");
}

The toISOFormat function in React Native with TypeScript converts a date in the format 2024-10-25 14:51:27.056551+03 to ISO format (e.g., 2024-10-25T14:51:27+03:00). It takes a date string, extracts the components using a regular expression, and throws an error if the format does not match the expected pattern.