te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to detect date format defined by browser? - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to detect date format defined by browser? - Stack Overflow

programmeradmin4浏览0评论

I'm using HTML5 input type=date field and because some browsers still don't support this feature, I would like to create error validation message for browsers that display just normal text field instead of date field. This error message should look like

Please enter date in format: ...

But I need to find the correct format, that the browser is set to. Is there any php/js/jQuery way how to find out this?

I'm using HTML5 input type=date field and because some browsers still don't support this feature, I would like to create error validation message for browsers that display just normal text field instead of date field. This error message should look like

Please enter date in format: ...

But I need to find the correct format, that the browser is set to. Is there any php/js/jQuery way how to find out this?

Share Improve this question edited Aug 20, 2021 at 8:07 Liam 29.7k28 gold badges138 silver badges200 bronze badges asked May 31, 2013 at 14:57 feri bacoferi baco 6354 gold badges8 silver badges16 bronze badges 5
  • Date formats are determined by the OS not the browser. You should dicate what format they should use, because I assume you're saving it to a database, so this saves you from changing the input for your db – Ryan B Commented May 31, 2013 at 15:08
  • I think this has been asked before <stackoverflow./questions/10193294/…> – jimmy Commented May 31, 2013 at 15:09
  • @jimmy That question is asking about the HTML5 calendar datepicker; this one is asking about international date formatting. – Blazemonger Commented May 31, 2013 at 15:18
  • See Is there any way to change input type="date" format?. It explains that the value attribute of the date input, according to the spec, must be in YYYY-MM-DD format. But the browser can present the date how it wants - usually either in that same format, or in the user's local format. – Rory O'Kane Commented May 31, 2013 at 15:30
  • Does this answer your question? How format JavaScript Date with regard to the browser culture? – Liam Commented Aug 20, 2021 at 8:08
Add a ment  | 

3 Answers 3

Reset to default 10

Thanks to @Jose Vega's answer I was able to find very easy way how to do it.

     var now=new Date(2013,11,31);
     var str=now.toLocaleDateString();
     str=str.replace("31","dd");
     str=str.replace("12","mm");
     str=str.replace("2013","yyyy");

Error message:

"Please enter date in format:" + str

I have used the globalize library to do something similar. I don't know if its functionality has what you are looking for, but I know it does a good job handling different cultures. I use the window.navigator.userLanguage to determine culture and then feed it to the globalize library to do its thing. I've had success when dealing with currency and numbers.

EDIT: See if this helps:

var now=new Date();
alert(now.toLocaleString());

taken from How format JavaScript Date with regard to the browser culture?

Reference Displaying proper date format depending on culture

Why not to allow users to enter date in any format they like.

E.g. i am tourist in the USA and the browser says me to use format mm/dd/YYYY instead of my native dd.mm.YYYY.

Just get any date entered by users and parse it with Date.parse()

发布评论

评论列表(0)

  1. 暂无评论