Write a function that takes in a string representing a time in 12-hour format (e.g. "10:45am" or "8:30pm") and returns a string representing the same time in 24-hour format (e.g. "10:45" or "20:30"). If the input string is invalid, the function should return null.
Function signature: `public static String convertTo24HourFormat(String time)`
🚀 Best Answers Get Featured in our LinkedIn Community based on Your Consent, To Increase Your Chances of Getting Interviewed. 🚀