Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有比我下面使用 JavaScript 或 PHP 将月份名称转换为月份编号更好的解决方案?
我确实喜欢这样:
$monNum = date('n',strtotime($staff->curMonth));
您可以保留键/值对的对象,其中键是月份名称,值是月份编号:
var months = { January: 1, February: 2, ... };
进而:
var monthNumber = months['April'];
或者:
var monthNumber = months.April;