ක්රමලේඛන භාෂාව අනුව දින ආකෘති
දින ආකෘතිගත කිරීම සඳහා කේත උදාහරණ
භාෂාව තෝරන්න
ඉක්මන් යොමුව: YYYY-MM-DD
ජනප්රිය භාෂාවල YYYY-MM-DD (ISO 8601) ලෙස දිනය ආකෘතිගත කරන ආකාරය:
💛 JavaScript
const date = new Date();
// Method 1: toISOString (recommended)
const formatted = date.toISOString().split('T')[0];
console.log(formatted); // Output: 2025-12-31
// Method 2: Manual formatting
const yyyy = date.getFullYear();
const mm = String(date.getMonth() + 1).padStart(2, '0');
const dd = String(date.getDate()).padStart(2, '0');
console.log(`${yyyy}-${mm}-${dd}`); // Output: 2025-12-31
🐍 Python
from datetime import datetime
date = datetime.now()
formatted = date.strftime('%Y-%m-%d')
print(formatted) # Output: 2025-12-31
🐘 PHP
<?php
echo date('Y-m-d'); // Output: 2025-12-31
🐬 MySQL
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d') AS formatted_date;
-- Output: 2025-12-31පොදු ආකෘති කේත
විවිධ භාෂා විවිධ ආකෘති කේත භාවිතා කරයි.
| අර්ථය | Python/PHP | JavaScript | SQL |
|---|---|---|---|
| වසර (ඉලක්කම් 4) | %Y | getFullYear() | %Y / YYYY |
| වසර (ඉලක්කම් 2) | %y | manual | %y / YY |
| මාසය (01-12) | %m | getMonth()+1 | %m / MM |
| මාස නාමය | %B | toLocaleDateString() | %M / Month |
| දිනය (01-31) | %d | getDate() | %d / DD |
ආකෘතිය අනුව බ්රවුස් කරන්න
දින ආකෘතිගත කිරීම සඳහා ඉඟි
හොඳම පුහුණුව: දත්ත සමුදායන්හි දින ගබඩා කිරීමේදී, සෑම විටම ISO 8601 (YYYY-MM-DD) ආකෘතිය භාවිතා කරන්න.
වේලා කලාප ඉඟිය: වේලා කලාප වෙනස්කම් ගැන සැලකිලිමත් වන්න.