-
Python:
import random import datetime start_date = datetime.date(2000, 1, 1) end_date = datetime.date(2023, 12, 31) random_date = start_date + datetime.timedelta(days=random.randint(0, (end_date - start_date).days)) print(random_date)
-
JavaScript:
const startDate = new Date(2000, 0, 1); const endDate = new Date(2023, 11, 31); const randomDate = new Date(startDate.getTime() + Math.random() * (endDate.getTime() - startDate.getTime())); console.log(randomDate.toDateString());
-
Java:
import java.time.LocalDate; import java.time.temporal.ChronoUnit; LocalDate startDate = LocalDate.of(2000, 1, 1); LocalDate endDate = LocalDate.of(2023, 12, 31); long days = startDate.until(endDate, ChronoUnit.DAYS); LocalDate randomDate = startDate.plusDays(new Random().nextInt((int) days + 1)); System.out.println(randomDate);
-
C#:
using System; DateTime startDate = new DateTime(2000, 1, 1); DateTime endDate = new DateTime(2023, 12, 31); Random random = new Random(); TimeSpan timeSpan = endDate - startDate; TimeSpan randomSpan = new TimeSpan((long)(random.NextDouble() * timeSpan.Ticks)); DateTime randomDate = startDate + randomSpan; Console.WriteLine(randomDate.ToShortDateString());