From 35f0a660906775c65ab1eedf6e2501c5de823cc4 Mon Sep 17 00:00:00 2001 From: 10bits Date: Sun, 19 Jul 2020 21:14:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99js=E5=BC=95=E6=93=8E=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?java.utf8ToGbk=E7=BC=96=E7=A0=81=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/JsExtensions.kt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/main/java/io/legado/app/help/JsExtensions.kt b/app/src/main/java/io/legado/app/help/JsExtensions.kt index a58fd7ce6..d12fc07ea 100644 --- a/app/src/main/java/io/legado/app/help/JsExtensions.kt +++ b/app/src/main/java/io/legado/app/help/JsExtensions.kt @@ -52,4 +52,10 @@ interface JsExtensions { fun timeFormat(time: Long): String { return dateFormat.format(Date(time)) } + //utf8编码转gbk编码 + fun utf8ToGbk(str: String): String { + val utf8 = String(str.toByteArray(charset("UTF-8"))) + val unicode = String(utf8.toByteArray(), charset("UTF-8")) + return String(unicode.toByteArray(charset("GBK"))) + } }