Django 帮助我无法翻译俄语中的日期字符串 -> 数字
设置.py
LANGUAGE_CODE = 'ru-RU'
USE_I18N = True
如果 USE_I18N = False,那么一切正常,但是
索引.html
<h5 class="date_verification">{{ device.data_next_colibr }}</h5>
<script src="{% static 'js/now_date.js' %}"></script>
2024 年 6 月 21 日发布
这是js代码
now_date.js
let date_verification = document.querySelector('.date_verification');
let date = Date.parse(new Date());
let date_ru = date_verification.innerHTML
let date_ver = Date.parse(date_verification.innerHTML.slice(0, -2));
console.log(date)
console.log(date_ver)
if (date >= date_ver){
console.log("просрочено");
document.getElementsByClassName('date_verification')[0].style= "color: #ff0000; font-weight: bold;";
}
else {
console.log("нормально");
document.getElementsByClassName('date_verification')[0].style= "color: #279A2B; font-weight: bold;";
}
这就是 console.log 输出的内容
1719579296000
now_date.js:8 21 июня 2024 г.
now_date.js:9 NaN
now_date.js:16 нормально
我会建议这个选项...
但你写这种格式YYYY-MM-DD会更方便。这样的一行可以立即转换为日期格式。