Вот несколько способов создания текущей даты в формате «ддммгггг» на различных языках программирования:
-
Python:
from datetime import date current_date = date.today().strftime("%d%m%Y") print(current_date)
-
JavaScript:
const today = new Date(); const day = String(today.getDate()).padStart(2, '0'); const month = String(today.getMonth() + 1).padStart(2, '0'); const year = today.getFullYear(); const current_date = day + month + year; console.log(current_date);
-
Java:
import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class Main { public static void main(String[] args) { LocalDate currentDate = LocalDate.now(); String formattedDate = currentDate.format(DateTimeFormatter.ofPattern("ddMMyyyy")); System.out.println(formattedDate); } }
-
C#:
using System; public class Program { public static void Main(string[] args) { DateTime currentDate = DateTime.Now; string formattedDate = currentDate.ToString("ddMMyyyy"); Console.WriteLine(formattedDate); } }
-
Рубин:
require 'date' current_date = Date.today.strftime("%d%m%Y") puts current_date
-
PHP:
$current_date = date("dmY"); echo $current_date;
-
Идем:
package main import ( "fmt" "time" ) func main() { currentDate := time.Now().Format("02012006") fmt.Println(currentDate) }
-
Скорость:
import Foundation let currentDate = DateFormatter.localizedString(from: Date(), dateStyle: .short, timeStyle: .none) let formattedDate = currentDate.replacingOccurrences(of: "/", with: "") print(formattedDate)
-
Ржавчина:
use chrono::prelude::*; fn main() { let current_date = Utc::today().format("%d%m%Y").to_string(); println!("{}", current_date); }
-
Котлин:
import java.time.LocalDate import java.time.format.DateTimeFormatter fun main() { val currentDate = LocalDate.now() val formattedDate = currentDate.format(DateTimeFormatter.ofPattern("ddMMyyyy")) println(formattedDate) }
-
C++:
#include <iostream> #include <ctime> #include <iomanip> int main() { std::time_t t = std::time(nullptr); std::tm* now = std::localtime(&t); std::cout << std::put_time(now, "%d%m%Y") << std::endl; return 0; }