查看Java中的以下代码片段.
final public class Main
{
public static void main(String[] args)
{
Locale.setDefault(new Locale("lt"));
String str = "\u00cc"; //setting Lithuanian as locale
System.out.println("Before case conversion is "+str+" and length is "+str.length());// Ì
String lowerCaseStr = str.toLowerCase();
System.out.println("Lower case is "+lowerCaseStr+" and length is "+lowerCaseStr.length());// i?`
}
}
Run Code Online (Sandbox Code Playgroud)
它显示以下输出.
在案件转换为Ì且长度为1之前
小写是i̇,长度是3
在第一个System.out.println()语句中,结果是准确的.但是,在第二个语句中,它显示的长度为3,实际上应为1.我不明白,为什么?
<ul>
<?php
$event_date = get_sub_field('event_date'); // 20150203
$event_date_format = DateTime::createFromFormat('Ymd', $event_date);
setlocale(LC_ALL, 'de_DE');
?>
<li>
<h6><?php echo $event_date_format->format('d');?>. <?php echo $event_date_format->format('F');?></h6>
<p><?php echo $event_date_format->format('H');?>:<?php echo $event_date_format->format('i');?></p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
这个的输出是
03. February
19:25
Run Code Online (Sandbox Code Playgroud)
为什么setlocale对此没有任何影响.我希望我的月份"F"像德语一样3. Feber 19:25
知道我在这里做错了吗?
更新1:
如果我尝试使用strftime()我突然得到一个不同的日期输出.它是德语但错了吗?
<ul>
<?php
$event_date = get_sub_field('event_date');
$event_date_format = DateTime::createFromFormat('Ymd', $event_date);
setlocale(LC_ALL, 'de_DE');
?>
<li>
<h6><?php echo $event_date_format->format('d');?>. <?php echo strftime('%B', $event_date);?></h6>
<p><?php echo $event_date_format->format('H');?>:<?php echo $event_date_format->format('i');?></p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
突然输出日期不是,03. February但03. August即使日期应该是2月.
有任何想法吗?
更新2:
这很奇怪.我刚刚$event_date在unix转换工具中在线查看了变量,我得到了这个...... …
如果我将darkmode设置为,AppCompatDelegate.setDefaultNightMode而系统不是黑暗的,则Configuration.setLocale无法使用。我将语言环境更改为,例如,从更改En为It,所有字符串仍然以系统语言显示。
如果我设置了与系统(Android 10)相同的NightMode,则没有问题。android 9或更低版本存在相同的问题:如果我在应用中设置了暗模式,并且更改了上下文语言,则活动会根据系统的语言显示文本。
为什么setlocale(LC_ALL, 'en_GB.UTF8');在Windows Server 2003 R2上返回false - Zend CE PHP 5.3.5?
有问题的功能:setlocale.
使用 Python 2.7
我正在编写一个抽象的网页抓取工具,但在显示(打印)某些字符时遇到了问题。
我收到回溯错误:UnicodeEncodeError: 'ascii' codec can't encode character u'\u2606' in position 5: ordinal not in range(128)从打印包含该字符的字符串。
我使用语言环境模块来找出我的操作系统支持的设置,虽然我不确定我是否应该使用语言环境来解决我的问题,并注意到默认设置(en_US', 'cp1252'). 我正在尝试将其更改为('en_US', 'utf-8')但遗憾的是无济于事。
#code for default settings
print locale.getdefaultlocale()
Run Code Online (Sandbox Code Playgroud)
这是我用来缩小语言环境设置选项的代码。(这里没有问题,代码只是让任何想要的人都可以跟随)
import locale
all = locale.locale_alias().items()
utfs = [(k,v) for k,v in all if 'utf' in k.lower() or 'utf' in v.lower()]
# utf settings starting with en
en_utfs = [(k,v) for k,v in utfs if k.lower()[:2].lower() == 'en' or
v.lower()[:2] == 'en'
print en_utfs
Run Code Online (Sandbox Code Playgroud)
这给出了输出:
[('en_ie.utf8@euro', …Run Code Online (Sandbox Code Playgroud) 我从 UI 传递语言代码和国家/地区代码来创建Locale对象。如何设置此 Locale 对象HttpServletRequest,以便在 Web 应用程序中的任何位置都可以使用此 Locale 对象HttpServletRequest.getLocale()?
我正在尝试将我的第二段代码的输出设为荷兰语。第一个代码给出了正确的输出,但是是英文的。我试图用荷兰语获得它,但通常我最终得到的是 01-01-1970、12-12-2015 或什么都没有。代码应该在本周的下周五给出,除非是过去的周一,否则下周就是周五。
我的工作代码是英文的。
<?php
$d = strtotime('today');
switch ($d) {
case strtotime('monday'):
case strtotime('friday'):
case strtotime('saturday'):
case strtotime('sunday'):
$ff = strtotime('next friday');
$ffn = date('l d M', $ff);
echo $ffn;
break;
case strtotime('tuesday'):
case strtotime('wednesday'):
case strtotime('thursday'):
$ff = strtotime('next friday' . '+ 7days');
$fft = date('l d M', $ff);
echo $fft;
break;
default:
echo "Something went wrong";
}
?>
Run Code Online (Sandbox Code Playgroud)
我的代码给出了荷兰语输出,但日期错误(它给出了今天的日期,而不是下周五/下周周五。)
顺便说一句,这是我在这里问的第一个问题,所以我可能有点含糊不清;)
遵循 Linode 的指南Copy a Disk Over SSH:
ssh root@xx.xx.xxx.xx "dd if=/dev/sdX " | dd of=/PathToLocalLocation/server.img
Run Code Online (Sandbox Code Playgroud)
xx.xx.xxx.xx您服务器的 IP在哪里,sdX-X代表您的驱动器分配的字母,并且您必须说明image's 的名称 =server.img
我遇到了这个问题(在我的本地计算机上):
bash: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)
Run Code Online (Sandbox Code Playgroud)
我进行了长时间的搜索,得到了很多结果,但都没有奏效,Lish也不是完整的解决方案。
我不能设置locales上Lish command line,无论我做什么....一切答案了有关于command-line在本地或服务器,而不是rescue-mode....想法?
我想使用 C 程序打印日语字符。我找到了一些日语字符的 Unicode 范围,将它们转换为十进制并使用 for 循环来打印它们:
setlocale(LC_ALL, "ja_JP.UTF8");
for (int i = 12784; i <= 12799; i++) {
printf("%c\n",i);
}
Run Code Online (Sandbox Code Playgroud)
locale.h 和 wchar.h 存在于标头中。
输出只给我 ????????? 人物。
请让我知道如何解决。
我们 在PHP中有setlocale函数.此功能有警告消息
每个进程维护语言环境信息,而不是每个线程.如果您在Windows上运行多线程服务器API(如IIS或Apache)上的PHP,则在脚本运行时可能会遇到区域设置的突然更改,尽管脚本本身从未调用过setlocale().这是因为其他脚本同时在同一进程的不同线程中运行,使用setlocale()更改进程范围的语言环境.
例如,带有miltithread设置的windows的apache.我在PHP项目中找到了这些代码行:
# ifdef PHP_WIN32
_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
# endif
Run Code Online (Sandbox Code Playgroud)
如果这段代码有效,为什么我们必须关心setlocale函数的警告?