Reputation: 103
I have made project with Expo version 48 and Date() is not working. In the below code "directDate" was working completely fine in Expo version 47 or separate javascript file.
Can anyone explain how to use Date() in expo version 48.
I am beginner and tried this for 7 hours to solve this, please help, thanks in advance.
App.js
import { StyleSheet, Text, View } from "react-native";
export default function App() {
const inputDate = "2023/05/20";
const directDate = new Date(inputDate); // Getting Invalid Date ?
return (
<View style={styles.container}>
<Text>Try Date - {directDate.toDateString()}</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
Upvotes: 0
Views: 344
Reputation: 36
In JS normally your Date uses dash instead of slash.
const inputDate = "2023-05-20";
const directDate = new Date(inputDate);
This date should now work as intended.
Upvotes: 0